OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "app/theme_provider.h" | 7 #include "app/theme_provider.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/chromeos/compact_navigation_bar.h" |
9 #include "chrome/browser/chromeos/main_menu.h" | 10 #include "chrome/browser/chromeos/main_menu.h" |
10 #include "chrome/browser/chromeos/status_area_view.h" | 11 #include "chrome/browser/chromeos/status_area_view.h" |
11 #include "chrome/browser/chromeos/panel_controller.h" | 12 #include "chrome/browser/chromeos/panel_controller.h" |
12 #include "chrome/browser/views/frame/browser_extender.h" | 13 #include "chrome/browser/views/frame/browser_extender.h" |
13 #include "chrome/browser/views/frame/browser_frame_gtk.h" | 14 #include "chrome/browser/views/frame/browser_frame_gtk.h" |
14 #include "chrome/browser/views/frame/browser_view.h" | 15 #include "chrome/browser/views/frame/browser_view.h" |
15 #include "chrome/browser/views/tabs/tab_overview_types.h" | 16 #include "chrome/browser/views/tabs/tab_overview_types.h" |
16 #include "chrome/browser/views/toolbar_view.h" | 17 #include "chrome/browser/views/toolbar_view.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
(...skipping 28 matching lines...) Expand all Loading... |
47 virtual void Init() { | 48 virtual void Init() { |
48 main_menu_ = new views::ImageButton(this); | 49 main_menu_ = new views::ImageButton(this); |
49 ThemeProvider* theme_provider = | 50 ThemeProvider* theme_provider = |
50 browser_view()->frame()->GetThemeProviderForFrame(); | 51 browser_view()->frame()->GetThemeProviderForFrame(); |
51 SkBitmap* image = theme_provider->GetBitmapNamed(IDR_MAIN_MENU_BUTTON); | 52 SkBitmap* image = theme_provider->GetBitmapNamed(IDR_MAIN_MENU_BUTTON); |
52 main_menu_->SetImage(views::CustomButton::BS_NORMAL, image); | 53 main_menu_->SetImage(views::CustomButton::BS_NORMAL, image); |
53 main_menu_->SetImage(views::CustomButton::BS_HOT, image); | 54 main_menu_->SetImage(views::CustomButton::BS_HOT, image); |
54 main_menu_->SetImage(views::CustomButton::BS_PUSHED, image); | 55 main_menu_->SetImage(views::CustomButton::BS_PUSHED, image); |
55 browser_view()->AddChildView(main_menu_); | 56 browser_view()->AddChildView(main_menu_); |
56 | 57 |
| 58 compact_navigation_bar_ = |
| 59 new CompactNavigationBar(browser_view()->browser()); |
| 60 browser_view()->AddChildView(compact_navigation_bar_); |
| 61 compact_navigation_bar_->Init(); |
| 62 // Disabled by default. |
| 63 // TODO(oshima): Get this info from preference. |
| 64 compact_navigation_bar_->SetVisible(false); |
| 65 |
57 status_area_ = new StatusAreaView( | 66 status_area_ = new StatusAreaView( |
58 browser_view()->browser(), | 67 browser_view()->browser(), |
59 browser_view()->GetWindow()->GetNativeWindow()); | 68 browser_view()->GetWindow()->GetNativeWindow()); |
60 browser_view()->AddChildView(status_area_); | 69 browser_view()->AddChildView(status_area_); |
61 status_area_->Init(); | 70 status_area_->Init(); |
62 | 71 |
63 InitSystemMenu(); | 72 InitSystemMenu(); |
64 MainMenu::ScheduleCreation(); | 73 MainMenu::ScheduleCreation(); |
65 | 74 |
66 // The ContextMenuController has to be set to a NonClientView but | 75 // The ContextMenuController has to be set to a NonClientView but |
(...skipping 13 matching lines...) Expand all Loading... |
80 // Layout main menu before tab strip. | 89 // Layout main menu before tab strip. |
81 gfx::Size main_menu_size = main_menu_->GetPreferredSize(); | 90 gfx::Size main_menu_size = main_menu_->GetPreferredSize(); |
82 main_menu_->SetBounds(bounds.x(), bounds.y(), | 91 main_menu_->SetBounds(bounds.x(), bounds.y(), |
83 main_menu_size.width(), bounds.height()); | 92 main_menu_size.width(), bounds.height()); |
84 | 93 |
85 // Layout status area after tab strip. | 94 // Layout status area after tab strip. |
86 gfx::Size status_size = status_area_->GetPreferredSize(); | 95 gfx::Size status_size = status_area_->GetPreferredSize(); |
87 status_area_->SetBounds(bounds.x() + bounds.width() - status_size.width(), | 96 status_area_->SetBounds(bounds.x() + bounds.width() - status_size.width(), |
88 bounds.y(), status_size.width(), | 97 bounds.y(), status_size.width(), |
89 status_size.height()); | 98 status_size.height()); |
| 99 int curx = bounds.x() + main_menu_size.width(); |
90 int width = bounds.width() - main_menu_size.width() - status_size.width(); | 100 int width = bounds.width() - main_menu_size.width() - status_size.width(); |
91 return gfx::Rect(bounds.x() + main_menu_size.width(), | 101 |
92 bounds.y(), | 102 if (compact_navigation_bar_->IsVisible()) { |
93 std::max(0, width), // in case there is no space left. | 103 gfx::Size cnb_bounds = compact_navigation_bar_->GetPreferredSize(); |
94 bounds.height()); | 104 compact_navigation_bar_->SetBounds(curx, bounds.y(), |
| 105 cnb_bounds.width(), bounds.height()); |
| 106 curx += cnb_bounds.width(); |
| 107 width -= cnb_bounds.width(); |
| 108 } |
| 109 width = std::max(0, width); // In case there is no space left. |
| 110 return gfx::Rect(curx, bounds.y(), width, bounds.height()); |
95 } | 111 } |
96 | 112 |
97 virtual bool NonClientHitTest(const gfx::Point& point) { | 113 virtual bool NonClientHitTest(const gfx::Point& point) { |
98 gfx::Point point_in_main_menu_coords(point); | 114 gfx::Point point_in_main_menu_coords(point); |
99 views::View::ConvertPointToView(browser_view(), main_menu_, | 115 views::View::ConvertPointToView(browser_view(), main_menu_, |
100 &point_in_main_menu_coords); | 116 &point_in_main_menu_coords); |
| 117 if (main_menu_->HitTest(point_in_main_menu_coords)) |
| 118 return true; |
101 | 119 |
102 gfx::Point point_in_status_area_coords(point); | 120 gfx::Point point_in_status_area_coords(point); |
103 views::View::ConvertPointToView(browser_view(), status_area_, | 121 views::View::ConvertPointToView(browser_view(), status_area_, |
104 &point_in_status_area_coords); | 122 &point_in_status_area_coords); |
| 123 if (status_area_->HitTest(point_in_status_area_coords)) |
| 124 return true; |
105 | 125 |
106 return main_menu_->HitTest(point_in_main_menu_coords) || | 126 if (compact_navigation_bar_->IsVisible()) { |
107 status_area_->HitTest(point_in_status_area_coords); | 127 gfx::Point point_in_cnb_coords(point); |
| 128 views::View::ConvertPointToView(browser_view(), |
| 129 compact_navigation_bar_, |
| 130 &point_in_cnb_coords); |
| 131 return compact_navigation_bar_->HitTest(point_in_cnb_coords); |
| 132 } |
| 133 return false; |
108 } | 134 } |
109 | 135 |
| 136 virtual void UpdateTitleBar() {} |
| 137 |
110 virtual void Show() { | 138 virtual void Show() { |
111 // TODO(oshima): PanelController seems to be doing something similar. | |
112 // Investigate if we need both. | |
113 TabOverviewTypes::instance()->SetWindowType( | 139 TabOverviewTypes::instance()->SetWindowType( |
114 GTK_WIDGET(GetBrowserWindow()->GetNativeWindow()), | 140 GTK_WIDGET(GetBrowserWindow()->GetNativeWindow()), |
115 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, | 141 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, |
116 NULL); | 142 NULL); |
117 } | 143 } |
118 | 144 |
| 145 virtual void Close() {} |
| 146 |
| 147 virtual void ActivationChanged() {} |
| 148 |
| 149 virtual bool ShouldForceHideToolbar() { |
| 150 return compact_navigation_bar_->IsVisible(); |
| 151 } |
| 152 |
| 153 virtual void ToggleCompactNavigationBar() { |
| 154 compact_navigation_bar_->SetVisible(!compact_navigation_bar_->IsVisible()); |
| 155 } |
| 156 |
119 private: | 157 private: |
120 // Creates system menu. | 158 // Creates system menu. |
121 void InitSystemMenu() { | 159 void InitSystemMenu() { |
122 system_menu_contents_.reset(new views::SimpleMenuModel(browser_view())); | 160 system_menu_contents_.reset(new views::SimpleMenuModel(browser_view())); |
123 system_menu_contents_->AddItemWithStringId(IDC_RESTORE_TAB, | 161 system_menu_contents_->AddItemWithStringId(IDC_RESTORE_TAB, |
124 IDS_RESTORE_TAB); | 162 IDS_RESTORE_TAB); |
125 system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); | 163 system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); |
126 system_menu_contents_->AddSeparator(); | 164 system_menu_contents_->AddSeparator(); |
127 system_menu_contents_->AddItemWithStringId(IDC_TASK_MANAGER, | 165 system_menu_contents_->AddItemWithStringId(IDC_TASK_MANAGER, |
128 IDS_TASK_MANAGER); | 166 IDS_TASK_MANAGER); |
(...skipping 16 matching lines...) Expand all Loading... |
145 // Main menu button. | 183 // Main menu button. |
146 views::ImageButton* main_menu_; | 184 views::ImageButton* main_menu_; |
147 | 185 |
148 // Status Area view. | 186 // Status Area view. |
149 StatusAreaView* status_area_; | 187 StatusAreaView* status_area_; |
150 | 188 |
151 // System menus | 189 // System menus |
152 scoped_ptr<views::SimpleMenuModel> system_menu_contents_; | 190 scoped_ptr<views::SimpleMenuModel> system_menu_contents_; |
153 scoped_ptr<views::Menu2> system_menu_menu_; | 191 scoped_ptr<views::Menu2> system_menu_menu_; |
154 | 192 |
| 193 // CompactNavigationBar view. |
| 194 CompactNavigationBar* compact_navigation_bar_; |
| 195 |
155 DISALLOW_COPY_AND_ASSIGN(NormalExtender); | 196 DISALLOW_COPY_AND_ASSIGN(NormalExtender); |
156 }; | 197 }; |
157 | 198 |
158 // PopupExtender class creates dedicated title window for popup window. | 199 // PopupExtender class creates dedicated title window for popup window. |
159 // The size and location of the created title window is controlled by | 200 // The size and location of the created title window is controlled by |
160 // by window manager. | 201 // by window manager. |
161 class PopupExtender : public BrowserExtender { | 202 class PopupExtender : public BrowserExtender { |
162 public: | 203 public: |
163 explicit PopupExtender(BrowserView* browser_view) | 204 explicit PopupExtender(BrowserView* browser_view) |
164 : BrowserExtender(browser_view) { | 205 : BrowserExtender(browser_view) { |
(...skipping 11 matching lines...) Expand all Loading... |
176 // The window manager needs the min size for popups. | 217 // The window manager needs the min size for popups. |
177 gfx::Rect bounds = window->GetBounds(); | 218 gfx::Rect bounds = window->GetBounds(); |
178 gtk_widget_set_size_request( | 219 gtk_widget_set_size_request( |
179 GTK_WIDGET(native_window), bounds.width(), bounds.height()); | 220 GTK_WIDGET(native_window), bounds.width(), bounds.height()); |
180 // If we don't explicitly resize here there is a race condition between | 221 // If we don't explicitly resize here there is a race condition between |
181 // the X Server and the window manager. Windows will appear with a default | 222 // the X Server and the window manager. Windows will appear with a default |
182 // size of 200x200 if this happens. | 223 // size of 200x200 if this happens. |
183 gtk_window_resize(native_window, bounds.width(), bounds.height()); | 224 gtk_window_resize(native_window, bounds.width(), bounds.height()); |
184 } | 225 } |
185 | 226 |
| 227 virtual gfx::Rect Layout(const gfx::Rect& bounds) { |
| 228 return bounds; |
| 229 } |
| 230 |
186 virtual bool NonClientHitTest(const gfx::Point& point) { | 231 virtual bool NonClientHitTest(const gfx::Point& point) { |
187 return false; | 232 return false; |
188 } | 233 } |
189 | 234 |
190 virtual void Show() { | 235 virtual void Show() { |
191 panel_controller_.reset(new PanelController(browser_view())); | 236 panel_controller_.reset(new PanelController(browser_view())); |
192 } | 237 } |
193 | 238 |
194 virtual void Close() { | 239 virtual void Close() { |
195 if (panel_controller_.get()) | 240 if (panel_controller_.get()) |
196 panel_controller_->Close(); | 241 panel_controller_->Close(); |
197 } | 242 } |
198 | 243 |
199 virtual void UpdateTitleBar() { | 244 virtual void UpdateTitleBar() { |
200 if (panel_controller_.get()) | 245 if (panel_controller_.get()) |
201 panel_controller_->UpdateTitleBar(); | 246 panel_controller_->UpdateTitleBar(); |
202 } | 247 } |
203 | 248 |
204 virtual void ActivationChanged() { | 249 virtual void ActivationChanged() { |
205 if (panel_controller_.get()) { | 250 if (panel_controller_.get()) { |
206 if (GetBrowserWindow()->IsActive()) | 251 if (GetBrowserWindow()->IsActive()) |
207 panel_controller_->OnFocusIn(); | 252 panel_controller_->OnFocusIn(); |
208 else | 253 else |
209 panel_controller_->OnFocusOut(); | 254 panel_controller_->OnFocusOut(); |
210 } | 255 } |
211 } | 256 } |
212 | 257 |
| 258 virtual bool ShouldForceHideToolbar() { |
| 259 // Always hide toolbar for popups. |
| 260 return true; |
| 261 } |
| 262 |
| 263 virtual void ToggleCompactNavigationBar() {} |
| 264 |
213 // Controls interactions with the window manager for popup panels. | 265 // Controls interactions with the window manager for popup panels. |
214 scoped_ptr<PanelController> panel_controller_; | 266 scoped_ptr<PanelController> panel_controller_; |
215 | 267 |
216 DISALLOW_COPY_AND_ASSIGN(PopupExtender); | 268 DISALLOW_COPY_AND_ASSIGN(PopupExtender); |
217 }; | 269 }; |
218 | 270 |
219 } // namespace | 271 } // namespace |
220 | 272 |
221 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
222 // BrowserExtender, public: | 274 // BrowserExtender, public: |
223 | 275 |
224 // static | 276 // static |
225 BrowserExtender* BrowserExtender::Create(BrowserView* browser_view) { | 277 BrowserExtender* BrowserExtender::Create(BrowserView* browser_view) { |
226 BrowserExtender* extender; | 278 BrowserExtender* extender; |
227 if (browser_view->browser()->type() & Browser::TYPE_POPUP) | 279 if (browser_view->browser()->type() & Browser::TYPE_POPUP) |
228 extender = new PopupExtender(browser_view); | 280 extender = new PopupExtender(browser_view); |
229 else | 281 else |
230 extender = new NormalExtender(browser_view); | 282 extender = new NormalExtender(browser_view); |
231 extender->Init(); | 283 extender->Init(); |
232 return extender; | 284 return extender; |
233 } | 285 } |
OLD | NEW |