OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/frame/browser_view.h" | 5 #include "chrome/browser/chromeos/frame/browser_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 layout_mode_button_ = static_cast<chromeos::LayoutModeButton*>(view); | 148 layout_mode_button_ = static_cast<chromeos::LayoutModeButton*>(view); |
149 break; | 149 break; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 // In the normal and the compact navigation bar mode, ChromeOS | 153 // In the normal and the compact navigation bar mode, ChromeOS |
154 // lays out compact navigation buttons and status views in the title | 154 // lays out compact navigation buttons and status views in the title |
155 // area. See Layout | 155 // area. See Layout |
156 virtual int LayoutTabStripRegion() OVERRIDE { | 156 virtual int LayoutTabStripRegion() OVERRIDE { |
157 if (browser_view_->IsFullscreen() || !browser_view_->IsTabStripVisible()) { | 157 if (browser_view_->IsFullscreen() || !browser_view_->IsTabStripVisible()) { |
158 status_area_->SetVisible(false); | 158 if (status_area_) { |
159 UpdateStatusAreaBoundsProperty(); | 159 status_area_->SetVisible(false); |
| 160 UpdateStatusAreaBoundsProperty(); |
| 161 } |
160 tabstrip_->SetVisible(false); | 162 tabstrip_->SetVisible(false); |
161 tabstrip_->SetBounds(0, 0, 0, 0); | 163 tabstrip_->SetBounds(0, 0, 0, 0); |
162 layout_mode_button_->SetVisible(false); | 164 layout_mode_button_->SetVisible(false); |
163 layout_mode_button_->SetBounds(0, 0, 0, 0); | 165 layout_mode_button_->SetBounds(0, 0, 0, 0); |
164 return 0; | 166 return 0; |
165 } | 167 } |
166 | 168 |
167 gfx::Rect tabstrip_bounds( | 169 gfx::Rect tabstrip_bounds( |
168 browser_view_->frame()->GetBoundsForTabStrip(tabstrip_)); | 170 browser_view_->frame()->GetBoundsForTabStrip(tabstrip_)); |
169 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); | 171 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); |
(...skipping 19 matching lines...) Expand all Loading... |
189 | 191 |
190 private: | 192 private: |
191 chromeos::BrowserView* chromeos_browser_view() { | 193 chromeos::BrowserView* chromeos_browser_view() { |
192 return static_cast<chromeos::BrowserView*>(browser_view_); | 194 return static_cast<chromeos::BrowserView*>(browser_view_); |
193 } | 195 } |
194 | 196 |
195 // Tests if the point is on one of views that are within the | 197 // Tests if the point is on one of views that are within the |
196 // considered title bar area of client view. | 198 // considered title bar area of client view. |
197 bool IsPointInViewsInTitleArea(const gfx::Point& point) | 199 bool IsPointInViewsInTitleArea(const gfx::Point& point) |
198 const { | 200 const { |
199 gfx::Point point_in_status_area_coords(point); | 201 if (status_area_) { |
200 views::View::ConvertPointToView(browser_view_, status_area_, | 202 gfx::Point point_in_status_area_coords(point); |
201 &point_in_status_area_coords); | 203 views::View::ConvertPointToView(browser_view_, status_area_, |
202 if (status_area_->HitTest(point_in_status_area_coords)) | 204 &point_in_status_area_coords); |
203 return true; | 205 if (status_area_->HitTest(point_in_status_area_coords)) |
204 | 206 return true; |
| 207 } |
205 gfx::Point point_in_layout_mode_button_coords(point); | 208 gfx::Point point_in_layout_mode_button_coords(point); |
206 views::View::ConvertPointToView(browser_view_, layout_mode_button_, | 209 views::View::ConvertPointToView(browser_view_, layout_mode_button_, |
207 &point_in_layout_mode_button_coords); | 210 &point_in_layout_mode_button_coords); |
208 if (layout_mode_button_->HitTest(point_in_layout_mode_button_coords)) | 211 if (layout_mode_button_->HitTest(point_in_layout_mode_button_coords)) |
209 return true; | 212 return true; |
210 | 213 |
211 return false; | 214 return false; |
212 } | 215 } |
213 | 216 |
214 // Lays out tabstrip, status area, and layout mode button in the title bar | 217 // Lays out tabstrip, status area, and layout mode button in the title bar |
215 // area (given by |bounds|). | 218 // area (given by |bounds|). |
216 int LayoutTitlebarComponents(const gfx::Rect& bounds) { | 219 int LayoutTitlebarComponents(const gfx::Rect& bounds) { |
217 if (bounds.IsEmpty()) | 220 if (bounds.IsEmpty()) |
218 return 0; | 221 return 0; |
219 | 222 |
220 const bool show_layout_mode_button = | 223 const bool show_layout_mode_button = |
221 chromeos_browser_view()->should_show_layout_mode_button(); | 224 chromeos_browser_view()->should_show_layout_mode_button(); |
222 | 225 |
223 tabstrip_->SetVisible(true); | 226 tabstrip_->SetVisible(true); |
224 status_area_->SetVisible( | 227 if (status_area_) { |
225 !chromeos_browser_view()->has_hide_status_area_property()); | 228 status_area_->SetVisible( |
| 229 !chromeos_browser_view()->has_hide_status_area_property()); |
| 230 } |
226 layout_mode_button_->SetVisible(show_layout_mode_button); | 231 layout_mode_button_->SetVisible(show_layout_mode_button); |
227 | 232 |
228 const gfx::Size layout_mode_button_size = | 233 const gfx::Size layout_mode_button_size = |
229 layout_mode_button_->GetPreferredSize(); | 234 layout_mode_button_->GetPreferredSize(); |
230 layout_mode_button_->SetBounds( | 235 layout_mode_button_->SetBounds( |
231 bounds.right() - layout_mode_button_size.width(), | 236 bounds.right() - layout_mode_button_size.width(), |
232 bounds.y(), | 237 bounds.y(), |
233 layout_mode_button_size.width(), | 238 layout_mode_button_size.width(), |
234 layout_mode_button_size.height()); | 239 layout_mode_button_size.height()); |
235 | 240 |
236 // Lay out status area after tab strip and before layout mode button (if | 241 if (status_area_) { |
237 // shown). | 242 // Lay out status area after tab strip and before layout mode button (if |
238 gfx::Size status_size = status_area_->GetPreferredSize(); | 243 // shown). |
239 const int status_right = | 244 gfx::Size status_size = status_area_->GetPreferredSize(); |
240 show_layout_mode_button ? | 245 const int status_right = |
241 layout_mode_button_->bounds().x() : | 246 show_layout_mode_button ? |
242 bounds.right(); | 247 layout_mode_button_->bounds().x() : |
243 status_area_->SetBounds( | 248 bounds.right(); |
244 status_right - status_size.width(), | 249 status_area_->SetBounds( |
245 bounds.y() + kStatusAreaVerticalAdjustment, | 250 status_right - status_size.width(), |
246 status_size.width(), | 251 bounds.y() + kStatusAreaVerticalAdjustment, |
247 status_size.height()); | 252 status_size.width(), |
248 UpdateStatusAreaBoundsProperty(); | 253 status_size.height()); |
| 254 UpdateStatusAreaBoundsProperty(); |
| 255 } |
249 tabstrip_->SetBounds(bounds.x(), bounds.y(), | 256 tabstrip_->SetBounds(bounds.x(), bounds.y(), |
250 std::max(0, status_area_->bounds().x() - bounds.x()), | 257 std::max(0, status_area_->bounds().x() - bounds.x()), |
251 bounds.height()); | 258 bounds.height()); |
252 return bounds.bottom(); | 259 return bounds.bottom(); |
253 } | 260 } |
254 | 261 |
255 // Updates |status_area_bounds_for_property_| based on the current bounds and | 262 // Updates |status_area_bounds_for_property_| based on the current bounds and |
256 // calls WmIpc::SetStatusBoundsProperty() if it changed. | 263 // calls WmIpc::SetStatusBoundsProperty() if it changed. |
257 void UpdateStatusAreaBoundsProperty() { | 264 void UpdateStatusAreaBoundsProperty() { |
| 265 if (!status_area_) |
| 266 return; |
258 gfx::Rect current_bounds; | 267 gfx::Rect current_bounds; |
259 if (status_area_->IsVisible()) { | 268 if (status_area_->IsVisible()) { |
260 gfx::Rect translated_bounds = | 269 gfx::Rect translated_bounds = |
261 status_area_->parent()->ConvertRectToWidget(status_area_->bounds()); | 270 status_area_->parent()->ConvertRectToWidget(status_area_->bounds()); |
262 // To avoid a dead zone across the top of the screen, | 271 // To avoid a dead zone across the top of the screen, |
263 // StatusAreaButton::HitTest() accepts clicks in the area between the top | 272 // StatusAreaButton::HitTest() accepts clicks in the area between the top |
264 // of its own bounds and the top of its parent view. Make the bounds that | 273 // of its own bounds and the top of its parent view. Make the bounds that |
265 // we report match. | 274 // we report match. |
266 current_bounds.SetRect( | 275 current_bounds.SetRect( |
267 translated_bounds.x(), | 276 translated_bounds.x(), |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 #if defined(TOOLKIT_USES_GTK) | 390 #if defined(TOOLKIT_USES_GTK) |
382 WmIpc::instance()->SetWindowType( | 391 WmIpc::instance()->SetWindowType( |
383 GTK_WIDGET(frame()->GetNativeWindow()), | 392 GTK_WIDGET(frame()->GetNativeWindow()), |
384 WM_IPC_WINDOW_CHROME_TOPLEVEL, | 393 WM_IPC_WINDOW_CHROME_TOPLEVEL, |
385 ¶ms); | 394 ¶ms); |
386 #endif | 395 #endif |
387 } | 396 } |
388 } | 397 } |
389 | 398 |
390 void BrowserView::FocusChromeOSStatus() { | 399 void BrowserView::FocusChromeOSStatus() { |
391 status_area_->SetPaneFocus(NULL); | 400 if (status_area_) |
| 401 status_area_->SetPaneFocus(NULL); |
392 } | 402 } |
393 | 403 |
394 views::LayoutManager* BrowserView::CreateLayoutManager() const { | 404 views::LayoutManager* BrowserView::CreateLayoutManager() const { |
395 return new BrowserViewLayout(); | 405 return new BrowserViewLayout(); |
396 } | 406 } |
397 | 407 |
398 void BrowserView::ChildPreferredSizeChanged(View* child) { | 408 void BrowserView::ChildPreferredSizeChanged(View* child) { |
399 Layout(); | 409 Layout(); |
400 } | 410 } |
401 | 411 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // StatusAreaButton::Delegate overrides. | 508 // StatusAreaButton::Delegate overrides. |
499 | 509 |
500 bool BrowserView::ShouldExecuteStatusAreaCommand( | 510 bool BrowserView::ShouldExecuteStatusAreaCommand( |
501 const views::View* button_view, int command_id) const { | 511 const views::View* button_view, int command_id) const { |
502 return true; | 512 return true; |
503 } | 513 } |
504 | 514 |
505 void BrowserView::ExecuteStatusAreaCommand( | 515 void BrowserView::ExecuteStatusAreaCommand( |
506 const views::View* button_view, int command_id) { | 516 const views::View* button_view, int command_id) { |
507 switch (command_id) { | 517 switch (command_id) { |
508 case StatusAreaViewChromeos::SHOW_NETWORK_OPTIONS: | 518 case StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS: |
509 browser()->OpenInternetOptionsDialog(); | 519 browser()->OpenInternetOptionsDialog(); |
510 break; | 520 break; |
511 case StatusAreaViewChromeos::SHOW_LANGUAGE_OPTIONS: | 521 case StatusAreaButton::Delegate::SHOW_LANGUAGE_OPTIONS: |
512 browser()->OpenLanguageOptionsDialog(); | 522 browser()->OpenLanguageOptionsDialog(); |
513 break; | 523 break; |
514 case StatusAreaViewChromeos::SHOW_SYSTEM_OPTIONS: | 524 case StatusAreaButton::Delegate::SHOW_SYSTEM_OPTIONS: |
515 browser()->OpenLanguageOptionsDialog(); | 525 browser()->OpenSystemOptionsDialog(); |
516 break; | 526 break; |
517 default: | 527 default: |
518 NOTREACHED(); | 528 NOTREACHED(); |
519 } | 529 } |
520 } | 530 } |
521 | 531 |
522 gfx::Font BrowserView::GetStatusAreaFont(const gfx::Font& font) const { | 532 gfx::Font BrowserView::GetStatusAreaFont(const gfx::Font& font) const { |
523 return font.DeriveFont(0, gfx::Font::BOLD); | 533 return font.DeriveFont(0, gfx::Font::BOLD); |
524 } | 534 } |
525 | 535 |
526 StatusAreaButton::TextStyle BrowserView::GetStatusAreaTextStyle() const { | 536 StatusAreaButton::TextStyle BrowserView::GetStatusAreaTextStyle() const { |
527 ThemeService* theme_service = | 537 ThemeService* theme_service = |
528 ThemeServiceFactory::GetForProfile(browser()->profile()); | 538 ThemeServiceFactory::GetForProfile(browser()->profile()); |
529 | 539 |
530 if (!theme_service->UsingDefaultTheme()) | 540 if (!theme_service->UsingDefaultTheme()) |
531 return StatusAreaButton::WHITE_HALOED; | 541 return StatusAreaButton::WHITE_HALOED; |
532 | 542 |
533 return IsOffTheRecord() ? | 543 return IsOffTheRecord() ? |
534 StatusAreaButton::WHITE_PLAIN : StatusAreaButton::GRAY_EMBOSSED; | 544 StatusAreaButton::WHITE_PLAIN : StatusAreaButton::GRAY_EMBOSSED; |
535 } | 545 } |
536 | 546 |
537 void BrowserView::ButtonVisibilityChanged(views::View* button_view) { | 547 void BrowserView::ButtonVisibilityChanged(views::View* button_view) { |
538 status_area_->UpdateButtonVisibility(); | 548 if (status_area_) |
| 549 status_area_->UpdateButtonVisibility(); |
539 } | 550 } |
540 | 551 |
541 // BrowserView, MessageLoopForUI::Observer implementation. | 552 // BrowserView, MessageLoopForUI::Observer implementation. |
542 | 553 |
543 #if defined(TOUCH_UI) || defined(USE_AURA) | 554 #if defined(TOUCH_UI) || defined(USE_AURA) |
544 base::EventStatus BrowserView::WillProcessEvent( | 555 base::EventStatus BrowserView::WillProcessEvent( |
545 const base::NativeEvent& event) OVERRIDE { | 556 const base::NativeEvent& event) OVERRIDE { |
546 return base::EVENT_CONTINUE; | 557 return base::EVENT_CONTINUE; |
547 } | 558 } |
548 | 559 |
(...skipping 19 matching lines...) Expand all Loading... |
568 } | 579 } |
569 } | 580 } |
570 } | 581 } |
571 #endif | 582 #endif |
572 | 583 |
573 // BrowserView protected: | 584 // BrowserView protected: |
574 | 585 |
575 void BrowserView::GetAccessiblePanes( | 586 void BrowserView::GetAccessiblePanes( |
576 std::vector<views::AccessiblePaneView*>* panes) { | 587 std::vector<views::AccessiblePaneView*>* panes) { |
577 ::BrowserView::GetAccessiblePanes(panes); | 588 ::BrowserView::GetAccessiblePanes(panes); |
578 panes->push_back(status_area_); | 589 if (status_area_) |
| 590 panes->push_back(status_area_); |
579 } | 591 } |
580 | 592 |
581 // BrowserView private. | 593 // BrowserView private. |
582 | 594 |
583 void BrowserView::InitSystemMenu() { | 595 void BrowserView::InitSystemMenu() { |
584 views::MenuItemView* menu = | 596 views::MenuItemView* menu = |
585 new views::MenuItemView(system_menu_delegate_.get()); | 597 new views::MenuItemView(system_menu_delegate_.get()); |
586 // MenuRunner takes ownership of menu. | 598 // MenuRunner takes ownership of menu. |
587 system_menu_runner_.reset(new views::MenuRunner(menu)); | 599 system_menu_runner_.reset(new views::MenuRunner(menu)); |
588 menu->AppendDelegateMenuItem(IDC_RESTORE_TAB); | 600 menu->AppendDelegateMenuItem(IDC_RESTORE_TAB); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 640 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
629 // Create a browser view for chromeos. | 641 // Create a browser view for chromeos. |
630 BrowserView* view; | 642 BrowserView* view; |
631 if (browser->is_type_popup() || browser->is_type_panel()) | 643 if (browser->is_type_popup() || browser->is_type_panel()) |
632 view = new chromeos::PanelBrowserView(browser); | 644 view = new chromeos::PanelBrowserView(browser); |
633 else | 645 else |
634 view = new chromeos::BrowserView(browser); | 646 view = new chromeos::BrowserView(browser); |
635 (new BrowserFrame(view))->InitBrowserFrame(); | 647 (new BrowserFrame(view))->InitBrowserFrame(); |
636 return view; | 648 return view; |
637 } | 649 } |
OLD | NEW |