Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_view.cc

Issue 75873002: [SiteChip] Add the basic painting of the site chip button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/command_updater.h" 14 #include "chrome/browser/command_updater.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/themes/theme_service.h" 17 #include "chrome/browser/themes/theme_service.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_command_controller.h" 19 #include "chrome/browser/ui/browser_command_controller.h"
19 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 21 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
21 #include "chrome/browser/ui/browser_instant_controller.h" 22 #include "chrome/browser/ui/browser_instant_controller.h"
22 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/global_error/global_error_service.h" 25 #include "chrome/browser/ui/global_error/global_error_service.h"
25 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 26 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
26 #include "chrome/browser/ui/omnibox/omnibox_view.h" 27 #include "chrome/browser/ui/omnibox/omnibox_view.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" 29 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
29 #include "chrome/browser/ui/view_ids.h" 30 #include "chrome/browser/ui/view_ids.h"
30 #include "chrome/browser/ui/views/frame/browser_view.h" 31 #include "chrome/browser/ui/views/frame/browser_view.h"
31 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 32 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
32 #include "chrome/browser/ui/views/location_bar/star_view.h" 33 #include "chrome/browser/ui/views/location_bar/star_view.h"
33 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 34 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
34 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 35 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
35 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 36 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
36 #include "chrome/browser/ui/views/toolbar/home_button.h" 37 #include "chrome/browser/ui/views/toolbar/home_button.h"
37 #include "chrome/browser/ui/views/toolbar/reload_button.h" 38 #include "chrome/browser/ui/views/toolbar/reload_button.h"
39 #include "chrome/browser/ui/views/toolbar/site_chip_view.h"
38 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" 40 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
39 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 41 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
40 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 42 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
41 #include "chrome/browser/upgrade_detector.h" 43 #include "chrome/browser/upgrade_detector.h"
42 #include "chrome/common/chrome_switches.h" 44 #include "chrome/common/chrome_switches.h"
43 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
44 #include "content/public/browser/browser_accessibility_state.h" 46 #include "content/public/browser/browser_accessibility_state.h"
45 #include "content/public/browser/notification_service.h" 47 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_view_host.h" 48 #include "content/public/browser/render_view_host.h"
47 #include "content/public/browser/user_metrics.h" 49 #include "content/public/browser/user_metrics.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 114
113 //////////////////////////////////////////////////////////////////////////////// 115 ////////////////////////////////////////////////////////////////////////////////
114 // ToolbarView, public: 116 // ToolbarView, public:
115 117
116 ToolbarView::ToolbarView(Browser* browser) 118 ToolbarView::ToolbarView(Browser* browser)
117 : back_(NULL), 119 : back_(NULL),
118 forward_(NULL), 120 forward_(NULL),
119 reload_(NULL), 121 reload_(NULL),
120 home_(NULL), 122 home_(NULL),
121 location_bar_(NULL), 123 location_bar_(NULL),
124 site_chip_view_(NULL),
122 browser_actions_(NULL), 125 browser_actions_(NULL),
123 app_menu_(NULL), 126 app_menu_(NULL),
124 browser_(browser) { 127 browser_(browser) {
125 set_id(VIEW_ID_TOOLBAR); 128 set_id(VIEW_ID_TOOLBAR);
126 129
127 chrome::AddCommandObserver(browser_, IDC_BACK, this); 130 chrome::AddCommandObserver(browser_, IDC_BACK, this);
128 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); 131 chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
129 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); 132 chrome::AddCommandObserver(browser_, IDC_RELOAD, this);
130 chrome::AddCommandObserver(browser_, IDC_HOME, this); 133 chrome::AddCommandObserver(browser_, IDC_HOME, this);
131 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); 134 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); 219 app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP));
217 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); 220 app_menu_->SetTooltipText(l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP));
218 app_menu_->set_id(VIEW_ID_APP_MENU); 221 app_menu_->set_id(VIEW_ID_APP_MENU);
219 222
220 // Always add children in order from left to right, for accessibility. 223 // Always add children in order from left to right, for accessibility.
221 AddChildView(back_); 224 AddChildView(back_);
222 AddChildView(forward_); 225 AddChildView(forward_);
223 AddChildView(reload_); 226 AddChildView(reload_);
224 AddChildView(home_); 227 AddChildView(home_);
225 AddChildView(location_bar_); 228 AddChildView(location_bar_);
229 if (chrome::ShouldDisplayOriginChip()) {
230 site_chip_view_ = new SiteChipView(this);
231 AddChildView(site_chip_view_);
232 }
226 AddChildView(browser_actions_); 233 AddChildView(browser_actions_);
227 AddChildView(app_menu_); 234 AddChildView(app_menu_);
228 235
229 LoadImages(); 236 LoadImages();
230 237
231 // Add any necessary badges to the menu item based on the system state. 238 // Add any necessary badges to the menu item based on the system state.
232 // Do this after |app_menu_| has been added as a bubble may be shown that 239 // Do this after |app_menu_| has been added as a bubble may be shown that
233 // needs the widget (widget found by way of app_menu_->GetWidget()). 240 // needs the widget (widget found by way of app_menu_->GetWidget()).
234 UpdateAppMenuState(); 241 UpdateAppMenuState();
235 242
236 location_bar_->Init(); 243 location_bar_->Init();
244 if (site_chip_view_)
245 site_chip_view_->Init();
237 show_home_button_.Init(prefs::kShowHomeButton, 246 show_home_button_.Init(prefs::kShowHomeButton,
238 browser_->profile()->GetPrefs(), 247 browser_->profile()->GetPrefs(),
239 base::Bind(&ToolbarView::OnShowHomeButtonChanged, 248 base::Bind(&ToolbarView::OnShowHomeButtonChanged,
240 base::Unretained(this))); 249 base::Unretained(this)));
241 250
242 browser_actions_->Init(); 251 browser_actions_->Init();
243 252
244 // Accessibility specific tooltip text. 253 // Accessibility specific tooltip text.
245 if (content::BrowserAccessibilityState::GetInstance()-> 254 if (content::BrowserAccessibilityState::GetInstance()->
246 IsAccessibleBrowser()) { 255 IsAccessibleBrowser()) {
247 back_->SetTooltipText( 256 back_->SetTooltipText(
248 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); 257 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK));
249 forward_->SetTooltipText( 258 forward_->SetTooltipText(
250 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); 259 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD));
251 } 260 }
252 } 261 }
253 262
254 void ToolbarView::Update(WebContents* tab) { 263 void ToolbarView::Update(WebContents* tab) {
255 if (location_bar_) 264 if (location_bar_)
256 location_bar_->Update(tab); 265 location_bar_->Update(tab);
266 if (site_chip_view_)
267 site_chip_view_->Update(tab);
257 268
258 if (browser_actions_) 269 if (browser_actions_)
259 browser_actions_->RefreshBrowserActionViews(); 270 browser_actions_->RefreshBrowserActionViews();
260 271
261 if (reload_) 272 if (reload_)
262 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); 273 reload_->set_menu_enabled(chrome::IsDebuggerAttachedToCurrentTab(browser_));
263 } 274 }
264 275
265 void ToolbarView::SetPaneFocusAndFocusAppMenu() { 276 void ToolbarView::SetPaneFocusAndFocusAppMenu() {
266 SetPaneFocus(app_menu_); 277 SetPaneFocus(app_menu_);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 gfx::Size ToolbarView::GetPreferredSize() { 479 gfx::Size ToolbarView::GetPreferredSize() {
469 if (is_display_mode_normal()) { 480 if (is_display_mode_normal()) {
470 int button_spacing = GetButtonSpacing(); 481 int button_spacing = GetButtonSpacing();
471 int min_width = kLeftEdgeSpacing + 482 int min_width = kLeftEdgeSpacing +
472 back_->GetPreferredSize().width() + button_spacing + 483 back_->GetPreferredSize().width() + button_spacing +
473 forward_->GetPreferredSize().width() + button_spacing + 484 forward_->GetPreferredSize().width() + button_spacing +
474 reload_->GetPreferredSize().width() + kStandardSpacing + 485 reload_->GetPreferredSize().width() + kStandardSpacing +
475 (show_home_button_.GetValue() ? 486 (show_home_button_.GetValue() ?
476 (home_->GetPreferredSize().width() + button_spacing) : 0) + 487 (home_->GetPreferredSize().width() + button_spacing) : 0) +
477 location_bar_->GetPreferredSize().width() + 488 location_bar_->GetPreferredSize().width() +
489 (site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0) +
478 browser_actions_->GetPreferredSize().width() + 490 browser_actions_->GetPreferredSize().width() +
479 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; 491 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing;
480 gfx::ImageSkia* normal_background = 492 gfx::ImageSkia* normal_background =
481 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); 493 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
482 return gfx::Size(min_width, 494 return gfx::Size(min_width,
483 normal_background->height() - content_shadow_height()); 495 normal_background->height() - content_shadow_height());
484 } 496 }
485 497
486 const int kPopupBottomSpacingGlass = 1; 498 const int kPopupBottomSpacingGlass = 1;
487 const int kPopupBottomSpacingNonGlass = 2; 499 const int kPopupBottomSpacingNonGlass = 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (show_home_button_.GetValue()) { 546 if (show_home_button_.GetValue()) {
535 home_->SetVisible(true); 547 home_->SetVisible(true);
536 home_->SetBounds(reload_->x() + reload_->width() + button_spacing, 548 home_->SetBounds(reload_->x() + reload_->width() + button_spacing,
537 child_y, home_->GetPreferredSize().width(), child_height); 549 child_y, home_->GetPreferredSize().width(), child_height);
538 } else { 550 } else {
539 home_->SetVisible(false); 551 home_->SetVisible(false);
540 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); 552 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height);
541 } 553 }
542 554
543 int browser_actions_width = browser_actions_->GetPreferredSize().width(); 555 int browser_actions_width = browser_actions_->GetPreferredSize().width();
556 int site_chip_width =
557 site_chip_view_ ? site_chip_view_->GetPreferredSize().width() : 0;
544 int app_menu_width = app_menu_->GetPreferredSize().width(); 558 int app_menu_width = app_menu_->GetPreferredSize().width();
545 int location_x = home_->x() + home_->width() + kStandardSpacing; 559 int location_x = home_->x() + home_->width() + kStandardSpacing;
546 int available_width = std::max(0, width() - kRightEdgeSpacing - 560 int available_width = std::max(0, width() - kRightEdgeSpacing -
547 app_menu_width - browser_actions_width - location_x); 561 app_menu_width - browser_actions_width - location_x);
548 562
563 // Cap site chip width at 1/2 the size available to the location bar.
564 site_chip_width = std::min(site_chip_width, available_width / 2);
565 available_width -= site_chip_width;
566
549 int location_height = location_bar_->GetPreferredSize().height(); 567 int location_height = location_bar_->GetPreferredSize().height();
550 int location_y = (height() - location_height + 1) / 2; 568 int location_y = (height() - location_height + 1) / 2;
551 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), 569 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0),
552 location_height); 570 location_height);
553 571
554 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, 572 int browser_actions_x = location_bar_->x() + location_bar_->width();
573 if (site_chip_view_) {
574 site_chip_view_->SetBounds(location_bar_->x() + location_bar_->width(),
575 child_y, site_chip_width, child_height);
576 browser_actions_x += site_chip_width;
577 }
578 browser_actions_->SetBounds(browser_actions_x, 0,
555 browser_actions_width, height()); 579 browser_actions_width, height());
580
556 // The browser actions need to do a layout explicitly, because when an 581 // The browser actions need to do a layout explicitly, because when an
557 // extension is loaded/unloaded/changed, BrowserActionContainer removes and 582 // extension is loaded/unloaded/changed, BrowserActionContainer removes and
558 // re-adds everything, regardless of whether it has a page action. For a 583 // re-adds everything, regardless of whether it has a page action. For a
559 // page action, browser action bounds do not change, as a result of which 584 // page action, browser action bounds do not change, as a result of which
560 // SetBounds does not do a layout at all. 585 // SetBounds does not do a layout at all.
561 // TODO(sidchat): Rework the above behavior so that explicit layout is not 586 // TODO(sidchat): Rework the above behavior so that explicit layout is not
562 // required. 587 // required.
563 browser_actions_->Layout(); 588 browser_actions_->Layout();
564 589
565 // Extend the app menu to the screen's right edge in maximized mode just like 590 // Extend the app menu to the screen's right edge in maximized mode just like
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 813
789 void ToolbarView::OnShowHomeButtonChanged() { 814 void ToolbarView::OnShowHomeButtonChanged() {
790 Layout(); 815 Layout();
791 SchedulePaint(); 816 SchedulePaint();
792 } 817 }
793 818
794 int ToolbarView::content_shadow_height() const { 819 int ToolbarView::content_shadow_height() const {
795 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 820 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
796 kContentShadowHeightAsh : kContentShadowHeight; 821 kContentShadowHeightAsh : kContentShadowHeight;
797 } 822 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698