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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 // NOTE: Don't remove the command observers here. This object gets destroyed | 217 // NOTE: Don't remove the command observers here. This object gets destroyed |
221 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is | 218 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
222 // already gone. | 219 // already gone. |
223 | 220 |
224 // TODO(kuan): Reset the search model observer in ~BrowserView before we lose | 221 // TODO(kuan): Reset the search model observer in ~BrowserView before we lose |
225 // browser. | 222 // browser. |
226 } | 223 } |
227 | 224 |
228 void ToolbarView::Init(views::View* location_bar_parent, | 225 void ToolbarView::Init(views::View* location_bar_parent, |
229 views::View* popup_parent_view) { | 226 views::View* popup_parent_view) { |
227 GetWidget()->AddObserver(this); | |
sky
2012/10/23 19:46:14
I get nervous when there is an add with no corresp
sky
2012/10/23 19:46:59
Sorry, this comment is a bit vague. I specifically
| |
228 | |
230 back_ = new views::ButtonDropDown(this, new BackForwardMenuModel( | 229 back_ = new views::ButtonDropDown(this, new BackForwardMenuModel( |
231 browser_, BackForwardMenuModel::BACKWARD_MENU)); | 230 browser_, BackForwardMenuModel::BACKWARD_MENU)); |
232 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 231 back_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
233 ui::EF_MIDDLE_MOUSE_BUTTON); | 232 ui::EF_MIDDLE_MOUSE_BUTTON); |
234 back_->set_tag(IDC_BACK); | 233 back_->set_tag(IDC_BACK); |
235 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, | 234 back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT, |
236 views::ImageButton::ALIGN_TOP); | 235 views::ImageButton::ALIGN_TOP); |
237 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); | 236 back_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_BACK)); |
238 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); | 237 back_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)); |
239 back_->set_id(VIEW_ID_BACK_BUTTON); | 238 back_->set_id(VIEW_ID_BACK_BUTTON); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 AddChildView(back_); | 305 AddChildView(back_); |
307 AddChildView(forward_); | 306 AddChildView(forward_); |
308 AddChildView(reload_); | 307 AddChildView(reload_); |
309 AddChildView(home_); | 308 AddChildView(home_); |
310 AddChildView(browser_actions_); | 309 AddChildView(browser_actions_); |
311 AddChildView(app_menu_); | 310 AddChildView(app_menu_); |
312 | 311 |
313 location_bar_->Init(popup_parent_view); | 312 location_bar_->Init(popup_parent_view); |
314 show_home_button_.Init(prefs::kShowHomeButton, | 313 show_home_button_.Init(prefs::kShowHomeButton, |
315 browser_->profile()->GetPrefs(), this); | 314 browser_->profile()->GetPrefs(), this); |
316 sideload_wipeout_bubble_shown_.Init( | |
317 prefs::kExtensionsSideloadWipeoutBubbleShown, | |
318 browser_->profile()->GetPrefs(), NULL); | |
319 | 315 |
320 browser_actions_->Init(); | 316 browser_actions_->Init(); |
321 | 317 |
322 // Accessibility specific tooltip text. | 318 // Accessibility specific tooltip text. |
323 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { | 319 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { |
324 back_->SetTooltipText( | 320 back_->SetTooltipText( |
325 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); | 321 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_BACK)); |
326 forward_->SetTooltipText( | 322 forward_->SetTooltipText( |
327 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); | 323 l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLTIP_FORWARD)); |
328 } | 324 } |
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 } | 325 } |
335 | 326 |
336 void ToolbarView::Update(WebContents* tab, bool should_restore_state) { | 327 void ToolbarView::Update(WebContents* tab, bool should_restore_state) { |
337 if (location_bar_) | 328 if (location_bar_) |
338 location_bar_->Update(should_restore_state ? tab : NULL); | 329 location_bar_->Update(should_restore_state ? tab : NULL); |
339 | 330 |
340 if (browser_actions_) | 331 if (browser_actions_) |
341 browser_actions_->RefreshBrowserActionViews(); | 332 browser_actions_->RefreshBrowserActionViews(); |
342 | 333 |
343 if (reload_) | 334 if (reload_) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 if ((disposition == CURRENT_TAB) && | 578 if ((disposition == CURRENT_TAB) && |
588 ((command == IDC_BACK) || (command == IDC_FORWARD))) { | 579 ((command == IDC_BACK) || (command == IDC_FORWARD))) { |
589 // Forcibly reset the location bar, since otherwise it won't discard any | 580 // 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 | 581 // ongoing user edits, since it doesn't realize this is a user-initiated |
591 // action. | 582 // action. |
592 location_bar_->Revert(); | 583 location_bar_->Revert(); |
593 } | 584 } |
594 chrome::ExecuteCommandWithDisposition(browser_, command, disposition); | 585 chrome::ExecuteCommandWithDisposition(browser_, command, disposition); |
595 } | 586 } |
596 | 587 |
588 void ToolbarView::OnWidgetVisibilityChanged(views::Widget* widget, | |
589 bool visible) { | |
590 if (visible) | |
591 DisabledExtensionsView::MaybeShow(browser_, app_menu_); | |
592 } | |
593 | |
597 //////////////////////////////////////////////////////////////////////////////// | 594 //////////////////////////////////////////////////////////////////////////////// |
598 // ToolbarView, content::NotificationObserver implementation: | 595 // ToolbarView, content::NotificationObserver implementation: |
599 | 596 |
600 void ToolbarView::Observe(int type, | 597 void ToolbarView::Observe(int type, |
601 const content::NotificationSource& source, | 598 const content::NotificationSource& source, |
602 const content::NotificationDetails& details) { | 599 const content::NotificationDetails& details) { |
603 switch (type) { | 600 switch (type) { |
604 case chrome::NOTIFICATION_PREF_CHANGED: { | 601 case chrome::NOTIFICATION_PREF_CHANGED: { |
605 std::string* pref_name = content::Details<std::string>(details).ptr(); | 602 std::string* pref_name = content::Details<std::string>(details).ptr(); |
606 if (*pref_name == prefs::kShowHomeButton) { | 603 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. | 1045 // LocationBarContainer is not a child of the ToolbarView. |
1049 gfx::Point origin(bounds.origin()); | 1046 gfx::Point origin(bounds.origin()); |
1050 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), | 1047 views::View::ConvertPointToTarget(this, location_bar_container_->parent(), |
1051 &origin); | 1048 &origin); |
1052 gfx::Rect target_bounds(origin, bounds.size()); | 1049 gfx::Rect target_bounds(origin, bounds.size()); |
1053 if (location_bar_container_->GetTargetBounds() != target_bounds) { | 1050 if (location_bar_container_->GetTargetBounds() != target_bounds) { |
1054 location_bar_container_->SetInToolbar(true); | 1051 location_bar_container_->SetInToolbar(true); |
1055 location_bar_container_->SetBoundsRect(target_bounds); | 1052 location_bar_container_->SetBoundsRect(target_bounds); |
1056 } | 1053 } |
1057 } | 1054 } |
OLD | NEW |