summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/frame/browser_view.cc
blob: cb08ab701fe9fa633b1230cb0914b75d3a41d42c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/views/frame/browser_view.h"

#include "chrome/browser/browser.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents.h"
#include "chrome/browser/tabs/tab_strip.h"
#include "chrome/browser/view_ids.h"
#include "chrome/browser/views/bookmark_bar_view.h"
#include "chrome/browser/views/go_button.h"
#include "chrome/browser/views/location_bar_view.h"
#include "chrome/browser/views/status_bubble.h"
#include "chrome/browser/views/toolbar_star_toggle.h"
#include "chrome/browser/views/toolbar_view.h"
#include "chrome/common/l10n_util.h"
#include "generated_resources.h"

// Status Bubble metrics.
static const int kStatusBubbleHeight = 20;
static const int kStatusBubbleOffset = 2;

///////////////////////////////////////////////////////////////////////////////
// BrowserView, public:

BrowserView::BrowserView(BrowserWindow* frame,
                         Browser* browser,
                         ChromeViews::Window* window,
                         ChromeViews::View* contents_view)
    : frame_(frame),
      browser_(browser),
      initialized_(false)
/*                     ,
      ClientView(window, contents_view) */ {
}

BrowserView::~BrowserView() {
}

void BrowserView::LayoutStatusBubble(int status_bubble_y) {
  status_bubble_->SetBounds(kStatusBubbleOffset,
                            status_bubble_y - kStatusBubbleHeight +
                            kStatusBubbleOffset,
                            GetWidth() / 3,
                            kStatusBubbleHeight);
}

///////////////////////////////////////////////////////////////////////////////
// BrowserView, BrowserWindow implementation:

void BrowserView::Init() {
  SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME));

  toolbar_ = new BrowserToolbarView(browser_->controller(), browser_);
  AddChildView(toolbar_);
  toolbar_->SetID(VIEW_ID_TOOLBAR);
  toolbar_->Init(browser_->profile());
  toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR));

  status_bubble_.reset(new StatusBubble(GetViewContainer()));
}

void BrowserView::Show(int command, bool adjust_to_fit) {
  frame_->Show(command, adjust_to_fit);
}

void BrowserView::Close() {
  frame_->Close();
}

void* BrowserView::GetPlatformID() {
  return frame_->GetPlatformID();
}

TabStrip* BrowserView::GetTabStrip() const {
  return frame_->GetTabStrip();
}

StatusBubble* BrowserView::GetStatusBubble() {
  return status_bubble_.get();
}

void BrowserView::ShelfVisibilityChanged() {
  frame_->ShelfVisibilityChanged();
}

void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) {
  frame_->SelectedTabToolbarSizeChanged(is_animating);
}

void BrowserView::UpdateTitleBar() {
  frame_->UpdateTitleBar();
}

void BrowserView::SetWindowTitle(const std::wstring& title) {
  frame_->SetWindowTitle(title);
}

void BrowserView::Activate() {
  frame_->Activate();
}

void BrowserView::FlashFrame() {
  frame_->FlashFrame();
}

void BrowserView::ShowTabContents(TabContents* contents) {
  frame_->ShowTabContents(contents);
}

void BrowserView::ContinueDetachConstrainedWindowDrag(
    const gfx::Point& mouse_pt,
    int frame_component) {
  frame_->ContinueDetachConstrainedWindowDrag(mouse_pt, frame_component);
}

void BrowserView::SizeToContents(const gfx::Rect& contents_bounds) {
  frame_->SizeToContents(contents_bounds);
}

void BrowserView::SetAcceleratorTable(
    std::map<ChromeViews::Accelerator, int>* accelerator_table) {
  frame_->SetAcceleratorTable(accelerator_table);
}

void BrowserView::ValidateThrobber() {
  frame_->ValidateThrobber();
}

gfx::Rect BrowserView::GetNormalBounds() {
  return frame_->GetNormalBounds();
}

bool BrowserView::IsMaximized() {
  return frame_->IsMaximized();
}

gfx::Rect BrowserView::GetBoundsForContentBounds(const gfx::Rect content_rect) {
  return frame_->GetBoundsForContentBounds(content_rect);
}

void BrowserView::InfoBubbleShowing() {
  frame_->InfoBubbleShowing();
}

void BrowserView::InfoBubbleClosing() {
  frame_->InfoBubbleClosing();
}

ToolbarStarToggle* BrowserView::GetStarButton() const {
  return toolbar_->star_button();
}

LocationBarView* BrowserView::GetLocationBarView() const {
  return toolbar_->GetLocationBarView();
}

GoButton* BrowserView::GetGoButton() const {
  return toolbar_->GetGoButton();
}

BookmarkBarView* BrowserView::GetBookmarkBarView() {
  return frame_->GetBookmarkBarView();
}

BrowserView* BrowserView::GetBrowserView() const {
  return NULL;
}

void BrowserView::UpdateToolbar(TabContents* contents,
                                bool should_restore_state) {
  toolbar_->Update(contents, should_restore_state);
}

void BrowserView::ProfileChanged(Profile* profile) {
  toolbar_->SetProfile(profile);
}

void BrowserView::FocusToolbar() {
  toolbar_->RequestFocus();
}

void BrowserView::DestroyBrowser() {
  frame_->DestroyBrowser();
}

///////////////////////////////////////////////////////////////////////////////
// BrowserView, ChromeViews::ClientView overrides:

/*
bool BrowserView::CanClose() const {
  return true;
}

int BrowserView::NonClientHitTest(const gfx::Point& point) {
  return HTCLIENT;
}
*/

///////////////////////////////////////////////////////////////////////////////
// BrowserView, ChromeViews::View overrides:

void BrowserView::Layout() {
  toolbar_->SetBounds(0, 0, GetWidth(), GetHeight());
}

void BrowserView::DidChangeBounds(const CRect& previous,
                                  const CRect& current) {
  Layout();
}

void BrowserView::ViewHierarchyChanged(bool is_add,
                                       ChromeViews::View* parent,
                                       ChromeViews::View* child) {
  if (is_add && child == this && GetViewContainer() && !initialized_) {
    Init();
    // Make sure not to call Init() twice if we get inserted into a different
    // ViewContainer.
    initialized_ = true;
  }
}