| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/command_updater.h" | 10 #include "chrome/browser/command_updater.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 // Top margin for the wrench menu badges (badge is placed in the upper right | 105 // Top margin for the wrench menu badges (badge is placed in the upper right |
| 106 // corner of the wrench menu). | 106 // corner of the wrench menu). |
| 107 const int kBadgeTopMargin = 2; | 107 const int kBadgeTopMargin = 2; |
| 108 | 108 |
| 109 // Added padding for search toolbar. | 109 // Added padding for search toolbar. |
| 110 const int kSearchTopButtonSpacing = 3; | 110 const int kSearchTopButtonSpacing = 3; |
| 111 const int kSearchTopLocationBarSpacing = 2; | 111 const int kSearchTopLocationBarSpacing = 2; |
| 112 const int kSearchToolbarSpacing = 5; | 112 const int kSearchToolbarSpacing = 5; |
| 113 | 113 |
| 114 // How often to show the disabled extension (sideload wipeout) bubble. | |
| 115 const int kShowSideloadWipeoutBubbleMax = 3; | |
| 116 | |
| 117 gfx::ImageSkia* kPopupBackgroundEdge = NULL; | 114 gfx::ImageSkia* kPopupBackgroundEdge = NULL; |
| 118 | 115 |
| 119 // The omnibox border has some additional shadow, so we use less vertical | 116 // The omnibox border has some additional shadow, so we use less vertical |
| 120 // spacing than ToolbarView::kVertSpacing. | 117 // spacing than ToolbarView::kVertSpacing. |
| 121 int location_bar_vert_spacing() { | 118 int location_bar_vert_spacing() { |
| 122 static int value = -1; | 119 static int value = -1; |
| 123 if (value == -1) { | 120 if (value == -1) { |
| 124 switch (ui::GetDisplayLayout()) { | 121 switch (ui::GetDisplayLayout()) { |
| 125 case ui::LAYOUT_ASH: | 122 case ui::LAYOUT_ASH: |
| 126 case ui::LAYOUT_DESKTOP: | 123 case ui::LAYOUT_DESKTOP: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 #endif | 207 #endif |
| 211 registrar_.Add(this, | 208 registrar_.Add(this, |
| 212 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE, | 209 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE, |
| 213 content::NotificationService::AllSources()); | 210 content::NotificationService::AllSources()); |
| 214 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 211 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 215 content::Source<Profile>(browser_->profile())); | 212 content::Source<Profile>(browser_->profile())); |
| 216 browser_->search_model()->AddObserver(this); | 213 browser_->search_model()->AddObserver(this); |
| 217 } | 214 } |
| 218 | 215 |
| 219 ToolbarView::~ToolbarView() { | 216 ToolbarView::~ToolbarView() { |
| 217 GetWidget()->RemoveObserver(this); |
| 218 |
| 220 // NOTE: Don't remove the command observers here. This object gets destroyed | 219 // NOTE: Don't remove the command observers here. This object gets destroyed |
| 221 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is | 220 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
| 222 // already gone. | 221 // already gone. |
| 223 | 222 |
| 224 // TODO(kuan): Reset the search model observer in ~BrowserView before we lose | 223 // TODO(kuan): Reset the search model observer in ~BrowserView before we lose |
| 225 // browser. | 224 // browser. |
| 226 } | 225 } |
| 227 | 226 |
| 228 void ToolbarView::Init(views::View* location_bar_parent, | 227 void ToolbarView::Init(views::View* location_bar_parent, |
| 229 views::View* popup_parent_view) { | 228 views::View* popup_parent_view) { |
| 229 GetWidget()->AddObserver(this); |
| 230 |
| 230 back_ = new views::ButtonDropDown(this, new BackForwardMenuModel( | 231 back_ = new views::ButtonDropDown(this, new BackForwardMenuModel( |
| 231 browser_, BackForwardMenuModel::BACKWARD_MENU)); | 232 browser_, BackForwardMenuModel::BACKWARD_MENU)); |
| 232 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 233 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
| 233 ui::EF_MIDDLE_MOUSE_BUTTON); | 234 ui::EF_MIDDLE_MOUSE_BUTTON); |
| 234 back_->set_tag(IDC_BACK); | 235 back_->set_tag(IDC_BACK); |
| 235 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, | 236 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, |
| 236 views::ImageButton::ALIGN_TOP); | 237 views::ImageButton::ALIGN_TOP); |
| 237 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); | 238 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); |
| 238 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); | 239 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); |
| 239 back_->set_id(VIEW_ID_BACK_BUTTON); | 240 back_->set_id(VIEW_ID_BACK_BUTTON); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 AddChildView(back_); | 307 AddChildView(back_); |
| 307 AddChildView(forward_); | 308 AddChildView(forward_); |
| 308 AddChildView(reload_); | 309 AddChildView(reload_); |
| 309 AddChildView(home_); | 310 AddChildView(home_); |
| 310 AddChildView(browser_actions_); | 311 AddChildView(browser_actions_); |
| 311 AddChildView(app_menu_); | 312 AddChildView(app_menu_); |
| 312 | 313 |
| 313 location_bar_->Init(popup_parent_view); | 314 location_bar_->Init(popup_parent_view); |
| 314 show_home_button_.Init(prefs::kShowHomeButton, | 315 show_home_button_.Init(prefs::kShowHomeButton, |
| 315 browser_->profile()->GetPrefs(), this); | 316 browser_->profile()->GetPrefs(), this); |
| 316 sideload_wipeout_bubble_shown_.Init( | |
| 317 prefs::kExtensionsSideloadWipeoutBubbleShown, | |
| 318 browser_->profile()->GetPrefs(), NULL); | |
| 319 | 317 |
| 320 browser_actions_->Init(); | 318 browser_actions_->Init(); |
| 321 | 319 |
| 322 // Accessibility specific tooltip text. | 320 // Accessibility specific tooltip text. |
| 323 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { | 321 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { |
| 324 back_->SetTooltipText( | 322 back_->SetTooltipText( |
| 325 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 323 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
| 326 forward_->SetTooltipText( | 324 forward_->SetTooltipText( |
| 327 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 325 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
| 328 } | 326 } |
| 329 | |
| 330 int bubble_shown_count = sideload_wipeout_bubble_shown_.GetValue(); | |
| 331 if (bubble_shown_count < kShowSideloadWipeoutBubbleMax && | |
| 332 DisabledExtensionsView::MaybeShow(browser_, app_menu_)) | |
| 333 sideload_wipeout_bubble_shown_.SetValue(++bubble_shown_count); | |
| 334 } | 327 } |
| 335 | 328 |
| 336 void ToolbarView::Update(WebContents* tab, bool should_restore_state) { | 329 void ToolbarView::Update(WebContents* tab, bool should_restore_state) { |
| 337 if (location_bar_) | 330 if (location_bar_) |
| 338 location_bar_->Update(should_restore_state ? tab : NULL); | 331 location_bar_->Update(should_restore_state ? tab : NULL); |
| 339 | 332 |
| 340 if (browser_actions_) | 333 if (browser_actions_) |
| 341 browser_actions_->RefreshBrowserActionViews(); | 334 browser_actions_->RefreshBrowserActionViews(); |
| 342 | 335 |
| 343 if (reload_) | 336 if (reload_) |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 if ((disposition == CURRENT_TAB) && | 580 if ((disposition == CURRENT_TAB) && |
| 588 ((command == IDC_BACK) || (command == IDC_FORWARD))) { | 581 ((command == IDC_BACK) || (command == IDC_FORWARD))) { |
| 589 // Forcibly reset the location bar, since otherwise it won't discard any | 582 // Forcibly reset the location bar, since otherwise it won't discard any |
| 590 // ongoing user edits, since it doesn't realize this is a user-initiated | 583 // ongoing user edits, since it doesn't realize this is a user-initiated |
| 591 // action. | 584 // action. |
| 592 location_bar_->Revert(); | 585 location_bar_->Revert(); |
| 593 } | 586 } |
| 594 chrome::ExecuteCommandWithDisposition(browser_, command, disposition); | 587 chrome::ExecuteCommandWithDisposition(browser_, command, disposition); |
| 595 } | 588 } |
| 596 | 589 |
| 590 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 591 bool visible) { |
| 592 if (visible) |
| 593 DisabledExtensionsView::MaybeShow(browser_, app_menu_); |
| 594 } |
| 595 |
| 597 //////////////////////////////////////////////////////////////////////////////// | 596 //////////////////////////////////////////////////////////////////////////////// |
| 598 // ToolbarView, content::NotificationObserver implementation: | 597 // ToolbarView, content::NotificationObserver implementation: |
| 599 | 598 |
| 600 void ToolbarView::Observe(int type, | 599 void ToolbarView::Observe(int type, |
| 601 const content::NotificationSource& source, | 600 const content::NotificationSource& source, |
| 602 const content::NotificationDetails& details) { | 601 const content::NotificationDetails& details) { |
| 603 switch (type) { | 602 switch (type) { |
| 604 case chrome::NOTIFICATION_PREF_CHANGED: { | 603 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 605 std::string* pref_name = content::Details<std::string>(details).ptr(); | 604 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 606 if (*pref_name == prefs::kShowHomeButton) { | 605 if (*pref_name == prefs::kShowHomeButton) { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 // LocationBarContainer is not a child of the ToolbarView. | 1047 // LocationBarContainer is not a child of the ToolbarView. |
| 1049 gfx::Point origin(bounds.origin()); | 1048 gfx::Point origin(bounds.origin()); |
| 1050 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), | 1049 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), |
| 1051 &origin); | 1050 &origin); |
| 1052 gfx::Rect target_bounds(origin, bounds.size()); | 1051 gfx::Rect target_bounds(origin, bounds.size()); |
| 1053 if (location_bar_container_->GetTargetBounds() != target_bounds) { | 1052 if (location_bar_container_->GetTargetBounds() != target_bounds) { |
| 1054 location_bar_container_->SetInToolbar(true); | 1053 location_bar_container_->SetInToolbar(true); |
| 1055 location_bar_container_->SetBoundsRect(target_bounds); | 1054 location_bar_container_->SetBoundsRect(target_bounds); |
| 1056 } | 1055 } |
| 1057 } | 1056 } |
| OLD | NEW |