OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/views/toolbar/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/i18n/number_formatting.h" | 9 #include "base/i18n/number_formatting.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
54 #include "content/public/browser/render_view_host.h" | 54 #include "content/public/browser/render_view_host.h" |
55 #include "content/public/browser/user_metrics.h" | 55 #include "content/public/browser/user_metrics.h" |
56 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
57 #include "content/public/browser/web_contents_view.h" | 57 #include "content/public/browser/web_contents_view.h" |
58 #include "grit/chromium_strings.h" | 58 #include "grit/chromium_strings.h" |
59 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
60 #include "grit/theme_resources.h" | 60 #include "grit/theme_resources.h" |
61 #include "ui/accessibility/ax_view_state.h" | 61 #include "ui/accessibility/ax_view_state.h" |
62 #include "ui/base/l10n/l10n_util.h" | 62 #include "ui/base/l10n/l10n_util.h" |
63 #include "ui/base/layout.h" | |
64 #include "ui/base/theme_provider.h" | 63 #include "ui/base/theme_provider.h" |
65 #include "ui/base/window_open_disposition.h" | 64 #include "ui/base/window_open_disposition.h" |
66 #include "ui/gfx/canvas.h" | 65 #include "ui/gfx/canvas.h" |
67 #include "ui/gfx/image/canvas_image_source.h" | 66 #include "ui/gfx/image/canvas_image_source.h" |
68 #include "ui/views/controls/menu/menu_listener.h" | 67 #include "ui/views/controls/menu/menu_listener.h" |
69 #include "ui/views/focus/view_storage.h" | 68 #include "ui/views/focus/view_storage.h" |
70 #include "ui/views/widget/tooltip_manager.h" | 69 #include "ui/views/widget/tooltip_manager.h" |
71 #include "ui/views/widget/widget.h" | 70 #include "ui/views/widget/widget.h" |
72 #include "ui/views/window/non_client_view.h" | 71 #include "ui/views/window/non_client_view.h" |
73 | 72 |
(...skipping 28 matching lines...) Expand all Loading... |
102 // our spacing to make it match. | 101 // our spacing to make it match. |
103 const int kLeftEdgeSpacing = 3; | 102 const int kLeftEdgeSpacing = 3; |
104 const int kRightEdgeSpacing = 2; | 103 const int kRightEdgeSpacing = 2; |
105 | 104 |
106 // Ash doesn't use a rounded content area and its top edge has an extra shadow. | 105 // Ash doesn't use a rounded content area and its top edge has an extra shadow. |
107 const int kContentShadowHeightAsh = 2; | 106 const int kContentShadowHeightAsh = 2; |
108 | 107 |
109 // Non-ash uses a rounded content area with no shadow in the assets. | 108 // Non-ash uses a rounded content area with no shadow in the assets. |
110 const int kContentShadowHeight = 0; | 109 const int kContentShadowHeight = 0; |
111 | 110 |
112 int GetButtonSpacing() { | |
113 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | |
114 ToolbarView::kStandardSpacing : 0; | |
115 } | |
116 | |
117 bool IsStreamlinedHostedAppsEnabled() { | 111 bool IsStreamlinedHostedAppsEnabled() { |
118 return CommandLine::ForCurrentProcess()->HasSwitch( | 112 return CommandLine::ForCurrentProcess()->HasSwitch( |
119 switches::kEnableStreamlinedHostedApps); | 113 switches::kEnableStreamlinedHostedApps); |
120 } | 114 } |
121 | 115 |
122 #if !defined(OS_CHROMEOS) | 116 #if !defined(OS_CHROMEOS) |
123 bool HasAshShell() { | 117 bool HasAshShell() { |
124 #if defined(USE_ASH) | 118 #if defined(USE_ASH) |
125 return ash::Shell::HasInstance(); | 119 return ash::Shell::HasInstance(); |
126 #else | 120 #else |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); | 404 DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); |
411 | 405 |
412 bool use_new_menu = false; | 406 bool use_new_menu = false; |
413 bool supports_new_separators = false; | 407 bool supports_new_separators = false; |
414 // TODO: remove this. | 408 // TODO: remove this. |
415 #if defined(USE_AURA) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) | 409 #if defined(USE_AURA) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
416 supports_new_separators = | 410 supports_new_separators = |
417 GetNativeTheme() == ui::NativeThemeAura::instance(); | 411 GetNativeTheme() == ui::NativeThemeAura::instance(); |
418 use_new_menu = supports_new_separators; | 412 use_new_menu = supports_new_separators; |
419 #endif | 413 #endif |
420 #if defined(OS_WIN) | |
421 use_new_menu = use_new_menu || ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; | |
422 #endif | |
423 | 414 |
424 wrench_menu_.reset(new WrenchMenu(browser_, use_new_menu, | 415 wrench_menu_.reset(new WrenchMenu(browser_, use_new_menu, |
425 supports_new_separators)); | 416 supports_new_separators)); |
426 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu)); | 417 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, use_new_menu)); |
427 wrench_menu_->Init(wrench_menu_model_.get()); | 418 wrench_menu_->Init(wrench_menu_model_.get()); |
428 | 419 |
429 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); | 420 FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); |
430 | 421 |
431 wrench_menu_->RunMenu(app_menu_); | 422 wrench_menu_->RunMenu(app_menu_); |
432 } | 423 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 ui::Accelerator* accelerator) { | 531 ui::Accelerator* accelerator) { |
541 return GetWidget()->GetAccelerator(command_id, accelerator); | 532 return GetWidget()->GetAccelerator(command_id, accelerator); |
542 } | 533 } |
543 | 534 |
544 //////////////////////////////////////////////////////////////////////////////// | 535 //////////////////////////////////////////////////////////////////////////////// |
545 // ToolbarView, views::View overrides: | 536 // ToolbarView, views::View overrides: |
546 | 537 |
547 gfx::Size ToolbarView::GetPreferredSize() { | 538 gfx::Size ToolbarView::GetPreferredSize() { |
548 gfx::Size size(location_bar_->GetPreferredSize()); | 539 gfx::Size size(location_bar_->GetPreferredSize()); |
549 if (is_display_mode_normal()) { | 540 if (is_display_mode_normal()) { |
550 int button_spacing = GetButtonSpacing(); | |
551 size.Enlarge( | 541 size.Enlarge( |
552 kLeftEdgeSpacing + back_->GetPreferredSize().width() + button_spacing + | 542 kLeftEdgeSpacing + back_->GetPreferredSize().width() + |
553 forward_->GetPreferredSize().width() + button_spacing + | 543 forward_->GetPreferredSize().width() + |
554 reload_->GetPreferredSize().width() + kStandardSpacing + | 544 reload_->GetPreferredSize().width() + kStandardSpacing + |
555 (show_home_button_.GetValue() ? | 545 (show_home_button_.GetValue() ? |
556 (home_->GetPreferredSize().width() + button_spacing) : 0) + | 546 home_->GetPreferredSize().width() : 0) + |
557 (origin_chip_view_->visible() ? | 547 (origin_chip_view_->visible() ? |
558 (origin_chip_view_->GetPreferredSize().width() + | 548 (origin_chip_view_->GetPreferredSize().width() + |
559 2 * kStandardSpacing) : | 549 2 * kStandardSpacing) : |
560 0) + | 550 0) + |
561 browser_actions_->GetPreferredSize().width() + | 551 browser_actions_->GetPreferredSize().width() + |
562 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, | 552 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing, |
563 0); | 553 0); |
564 gfx::ImageSkia* normal_background = | 554 gfx::ImageSkia* normal_background = |
565 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 555 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
566 size.SetToMax( | 556 size.SetToMax( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 // http://crbug.com/5540 | 593 // http://crbug.com/5540 |
604 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 594 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
605 int back_width = back_->GetPreferredSize().width(); | 595 int back_width = back_->GetPreferredSize().width(); |
606 if (maximized) { | 596 if (maximized) { |
607 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 597 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); |
608 back_->SetLeadingMargin(kLeftEdgeSpacing); | 598 back_->SetLeadingMargin(kLeftEdgeSpacing); |
609 } else { | 599 } else { |
610 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 600 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); |
611 back_->SetLeadingMargin(0); | 601 back_->SetLeadingMargin(0); |
612 } | 602 } |
613 int button_spacing = GetButtonSpacing(); | 603 int next_element_x = back_->bounds().right(); |
614 int next_element_x = back_->bounds().right() + button_spacing; | |
615 | 604 |
616 forward_->SetBounds(next_element_x, child_y, | 605 forward_->SetBounds(next_element_x, child_y, |
617 forward_->GetPreferredSize().width(), child_height); | 606 forward_->GetPreferredSize().width(), child_height); |
618 next_element_x = forward_->bounds().right() + button_spacing; | 607 next_element_x = forward_->bounds().right(); |
619 | 608 |
620 reload_->SetBounds(next_element_x, child_y, | 609 reload_->SetBounds(next_element_x, child_y, |
621 reload_->GetPreferredSize().width(), child_height); | 610 reload_->GetPreferredSize().width(), child_height); |
622 next_element_x = reload_->bounds().right(); | 611 next_element_x = reload_->bounds().right(); |
623 | 612 |
624 if (show_home_button_.GetValue() || | 613 if (show_home_button_.GetValue() || |
625 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())) { | 614 (browser_->is_app() && IsStreamlinedHostedAppsEnabled())) { |
626 home_->SetVisible(true); | 615 home_->SetVisible(true); |
627 home_->SetBounds(next_element_x + button_spacing, child_y, | 616 home_->SetBounds(next_element_x, child_y, |
628 home_->GetPreferredSize().width(), child_height); | 617 home_->GetPreferredSize().width(), child_height); |
629 } else { | 618 } else { |
630 home_->SetVisible(false); | 619 home_->SetVisible(false); |
631 home_->SetBounds(next_element_x, child_y, 0, child_height); | 620 home_->SetBounds(next_element_x, child_y, 0, child_height); |
632 } | 621 } |
633 next_element_x = home_->bounds().right() + kStandardSpacing; | 622 next_element_x = home_->bounds().right() + kStandardSpacing; |
634 | 623 |
635 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 624 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
636 int app_menu_width = app_menu_->GetPreferredSize().width(); | 625 int app_menu_width = app_menu_->GetPreferredSize().width(); |
637 int available_width = std::max(0, width() - kRightEdgeSpacing - | 626 int available_width = std::max(0, width() - kRightEdgeSpacing - |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 874 |
886 void ToolbarView::OnShowHomeButtonChanged() { | 875 void ToolbarView::OnShowHomeButtonChanged() { |
887 Layout(); | 876 Layout(); |
888 SchedulePaint(); | 877 SchedulePaint(); |
889 } | 878 } |
890 | 879 |
891 int ToolbarView::content_shadow_height() const { | 880 int ToolbarView::content_shadow_height() const { |
892 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 881 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
893 kContentShadowHeightAsh : kContentShadowHeight; | 882 kContentShadowHeightAsh : kContentShadowHeight; |
894 } | 883 } |
OLD | NEW |