Chromium Code Reviews| 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/extensions/extension_view_host.h" | 12 #include "chrome/browser/extensions/extension_view_host.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/view_ids.h" | 19 #include "chrome/browser/ui/view_ids.h" |
| 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
| 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 25 #include "chrome/common/extensions/command.h" | 25 #include "chrome/common/extensions/command.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/pref_names.h" | 28 #include "extensions/browser/pref_names.h" |
| 29 #include "extensions/browser/runtime_data.h" | 29 #include "extensions/browser/runtime_data.h" |
| 30 #include "extensions/common/feature_switch.h" | |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 32 #include "grit/ui_resources.h" | 33 #include "grit/ui_resources.h" |
| 33 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
| 34 #include "ui/accessibility/ax_view_state.h" | 35 #include "ui/accessibility/ax_view_state.h" |
| 35 #include "ui/base/dragdrop/drag_utils.h" | 36 #include "ui/base/dragdrop/drag_utils.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/nine_image_painter_factory.h" | 38 #include "ui/base/nine_image_painter_factory.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/theme_provider.h" | 40 #include "ui/base/theme_provider.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // Horizontal spacing between most items in the container, as well as after the | 54 // Horizontal spacing between most items in the container, as well as after the |
| 54 // last item or chevron (if visible). | 55 // last item or chevron (if visible). |
| 55 const int kItemSpacing = ToolbarView::kStandardSpacing; | 56 const int kItemSpacing = ToolbarView::kStandardSpacing; |
| 56 | 57 |
| 57 // Horizontal spacing before the chevron (if visible). | 58 // Horizontal spacing before the chevron (if visible). |
| 58 const int kChevronSpacing = kItemSpacing - 2; | 59 const int kChevronSpacing = kItemSpacing - 2; |
| 59 | 60 |
| 61 // Padding to make sure the badge appears in the right location vertically when | |
| 62 // in overflow mode (inside the app menu, aka. hamburger menu). | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: hamburger again
Finnur
2014/07/02 16:59:56
Done.
| |
| 63 const int kPaddingForBadge = 9; | |
|
Peter Kasting
2014/06/30 23:36:33
Can we compute this value automatically from the i
Finnur
2014/07/02 16:59:56
Updated comment (see my next reply also, applies t
| |
| 64 | |
| 65 // The maximum number of icons to show per row when in overflow mode (showing | |
| 66 // icons in the application menu). | |
| 67 #if defined(OS_LINUX) | |
| 68 const int kIconsPerMenuRow = 8; // The menu on Linux is wider. | |
|
Peter Kasting
2014/06/30 23:36:33
Again, can we compute this from the container or p
Finnur
2014/07/02 16:59:56
Yes, definitely. I don't have time for it in this
| |
| 69 #else | |
| 70 const int kIconsPerMenuRow = 7; | |
| 71 #endif | |
| 72 | |
| 60 // A version of MenuButton with almost empty insets to fit properly on the | 73 // A version of MenuButton with almost empty insets to fit properly on the |
| 61 // toolbar. | 74 // toolbar. |
| 62 class ChevronMenuButton : public views::MenuButton { | 75 class ChevronMenuButton : public views::MenuButton { |
| 63 public: | 76 public: |
| 64 ChevronMenuButton(views::ButtonListener* listener, | 77 ChevronMenuButton(views::ButtonListener* listener, |
| 65 const base::string16& text, | 78 const base::string16& text, |
| 66 views::MenuButtonListener* menu_button_listener, | 79 views::MenuButtonListener* menu_button_listener, |
| 67 bool show_menu_marker) | 80 bool show_menu_marker) |
| 68 : views::MenuButton(listener, | 81 : views::MenuButton(listener, |
| 69 text, | 82 text, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 87 }; | 100 }; |
| 88 | 101 |
| 89 } // namespace | 102 } // namespace |
| 90 | 103 |
| 91 // static | 104 // static |
| 92 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 105 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 93 | 106 |
| 94 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
| 95 // BrowserActionsContainer | 108 // BrowserActionsContainer |
| 96 | 109 |
| 97 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, | 110 BrowserActionsContainer::BrowserActionsContainer( |
| 98 View* owner_view) | 111 Browser* browser, View* owner_view, BrowserActionsContainer* main_container) |
|
Peter Kasting
2014/06/30 23:36:33
Nit: One arg per line
Finnur
2014/07/02 16:59:56
Done.
| |
| 99 : profile_(browser->profile()), | 112 : profile_(browser->profile()), |
| 100 browser_(browser), | 113 browser_(browser), |
| 101 owner_view_(owner_view), | 114 owner_view_(owner_view), |
| 115 main_container_(main_container), | |
| 102 popup_(NULL), | 116 popup_(NULL), |
| 103 popup_button_(NULL), | 117 popup_button_(NULL), |
| 104 model_(NULL), | 118 model_(NULL), |
| 105 container_width_(0), | 119 container_width_(0), |
| 120 resize_area_(NULL), | |
| 106 chevron_(NULL), | 121 chevron_(NULL), |
| 107 overflow_menu_(NULL), | 122 overflow_menu_(NULL), |
| 108 suppress_chevron_(false), | 123 suppress_chevron_(false), |
| 109 resize_amount_(0), | 124 resize_amount_(0), |
| 110 animation_target_size_(0), | 125 animation_target_size_(0), |
| 111 drop_indicator_position_(-1), | 126 drop_indicator_position_(-1), |
| 112 task_factory_(this), | 127 task_factory_(this), |
| 113 show_menu_task_factory_(this) { | 128 show_menu_task_factory_(this) { |
| 114 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 129 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 115 | 130 |
| 116 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 131 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
| 117 if (model_) | 132 if (model_) |
| 118 model_->AddObserver(this); | 133 model_->AddObserver(this); |
| 119 | 134 |
| 120 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 135 bool overflow_experiment = |
| 121 browser->profile(), | 136 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
| 122 owner_view->GetFocusManager(), | 137 DCHECK(!handling_overflow() || overflow_experiment); |
| 123 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | |
| 124 this)); | |
| 125 | 138 |
| 126 resize_animation_.reset(new gfx::SlideAnimation(this)); | 139 if (!handling_overflow()) { |
| 127 resize_area_ = new views::ResizeArea(this); | 140 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 128 AddChildView(resize_area_); | 141 browser->profile(), |
| 142 owner_view->GetFocusManager(), | |
| 143 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | |
| 144 this)); | |
| 129 | 145 |
| 130 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | 146 resize_animation_.reset(new gfx::SlideAnimation(this)); |
| 131 chevron_->EnableCanvasFlippingForRTLUI(true); | 147 resize_area_ = new views::ResizeArea(this); |
| 132 chevron_->SetAccessibleName( | 148 AddChildView(resize_area_); |
| 133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 149 |
| 134 chevron_->SetVisible(false); | 150 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside |
| 135 AddChildView(chevron_); | 151 // the hamburger menu. |
| 152 if (!overflow_experiment) { | |
| 153 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | |
| 154 chevron_->SetBorder(views::Border::NullBorder()); | |
| 155 chevron_->EnableCanvasFlippingForRTLUI(true); | |
| 156 chevron_->SetAccessibleName( | |
| 157 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | |
| 158 chevron_->SetVisible(false); | |
| 159 AddChildView(chevron_); | |
| 160 } | |
| 161 } | |
| 136 } | 162 } |
| 137 | 163 |
| 138 BrowserActionsContainer::~BrowserActionsContainer() { | 164 BrowserActionsContainer::~BrowserActionsContainer() { |
| 139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 165 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 140 observers_, | 166 observers_, |
| 141 OnBrowserActionsContainerDestroyed()); | 167 OnBrowserActionsContainerDestroyed()); |
| 142 | 168 |
| 143 if (overflow_menu_) | 169 if (overflow_menu_) |
| 144 overflow_menu_->set_observer(NULL); | 170 overflow_menu_->set_observer(NULL); |
| 145 if (model_) | 171 if (model_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 void BrowserActionsContainer::ExecuteExtensionCommand( | 252 void BrowserActionsContainer::ExecuteExtensionCommand( |
| 227 const extensions::Extension* extension, | 253 const extensions::Extension* extension, |
| 228 const extensions::Command& command) { | 254 const extensions::Command& command) { |
| 229 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 255 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
| 230 // instance. | 256 // instance. |
| 231 DCHECK(!command.global()); | 257 DCHECK(!command.global()); |
| 232 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 258 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 233 command.accelerator()); | 259 command.accelerator()); |
| 234 } | 260 } |
| 235 | 261 |
| 262 bool BrowserActionsContainer::ShownInsideMenu() const { | |
| 263 return handling_overflow(); | |
| 264 } | |
| 265 | |
| 236 void BrowserActionsContainer::AddObserver( | 266 void BrowserActionsContainer::AddObserver( |
| 237 BrowserActionsContainerObserver* observer) { | 267 BrowserActionsContainerObserver* observer) { |
| 238 observers_.AddObserver(observer); | 268 observers_.AddObserver(observer); |
| 239 } | 269 } |
| 240 | 270 |
| 241 void BrowserActionsContainer::RemoveObserver( | 271 void BrowserActionsContainer::RemoveObserver( |
| 242 BrowserActionsContainerObserver* observer) { | 272 BrowserActionsContainerObserver* observer) { |
| 243 observers_.RemoveObserver(observer); | 273 observers_.RemoveObserver(observer); |
| 244 } | 274 } |
| 245 | 275 |
| 246 gfx::Size BrowserActionsContainer::GetPreferredSize() const { | 276 gfx::Size BrowserActionsContainer::GetPreferredSize() const { |
| 277 size_t our_icon_count = browser_action_views_.size() - | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Remove "our_", that's just odd
Finnur
2014/07/02 16:59:56
Done.
| |
| 278 (handling_overflow() ? main_container_->VisibleBrowserActions() : 0); | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: For example, this is a place where "main_cont
Finnur
2014/07/02 16:59:56
I wrote this CL a few months back and had to put i
| |
| 279 | |
| 280 // If there are no actions to show, or we are in overflow mode and the main | |
| 281 // container is already showing them all, then no further work is required. | |
| 282 if (our_icon_count == 0) | |
| 283 return gfx::Size(); | |
| 284 | |
| 285 if (handling_overflow()) { | |
| 286 // When in overflow, y is multiline, so the pixel count is IconHeight() | |
| 287 // times the number of rows needed. | |
| 288 return gfx::Size( | |
| 289 IconCountToWidth(kIconsPerMenuRow, false), | |
| 290 (((our_icon_count - 1) / kIconsPerMenuRow) + 1) * IconHeight()); | |
| 291 } | |
| 292 | |
| 247 // We calculate the size of the view by taking the current width and | 293 // We calculate the size of the view by taking the current width and |
| 248 // subtracting resize_amount_ (the latter represents how far the user is | 294 // subtracting resize_amount_ (the latter represents how far the user is |
| 249 // resizing the view or, if animating the snapping, how far to animate it). | 295 // resizing the view or, if animating the snapping, how far to animate it). |
| 250 // But we also clamp it to a minimum size and the maximum size, so that the | 296 // But we also clamp it to a minimum size and the maximum size, so that the |
| 251 // container can never shrink too far or take up more space than it needs. In | 297 // container can never shrink too far or take up more space than it needs. |
| 252 // other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). | 298 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). |
| 253 int preferred_width = std::min( | 299 int preferred_width = std::min( |
| 254 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), | 300 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), |
| 255 IconCountToWidth(-1, false)); | 301 IconCountToWidth(-1, false)); |
| 256 // Height will be ignored by the ToolbarView. | 302 return gfx::Size(preferred_width, IconHeight()); |
| 257 return gfx::Size(preferred_width, 0); | |
| 258 } | 303 } |
| 259 | 304 |
| 260 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 305 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
| 261 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); | 306 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); |
| 262 // Height will be ignored by the ToolbarView. | 307 return gfx::Size(min_width, IconHeight()); |
| 263 return gfx::Size(min_width, 0); | |
| 264 } | 308 } |
| 265 | 309 |
| 266 void BrowserActionsContainer::Layout() { | 310 void BrowserActionsContainer::Layout() { |
| 267 if (browser_action_views_.empty()) { | 311 if (browser_action_views_.empty()) { |
| 268 SetVisible(false); | 312 SetVisible(false); |
| 269 return; | 313 return; |
| 270 } | 314 } |
| 271 | 315 |
| 272 SetVisible(true); | 316 SetVisible(true); |
| 273 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 317 if (resize_area_) |
| 318 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | |
| 274 | 319 |
| 275 // If the icons don't all fit, show the chevron (unless suppressed). | 320 // If the icons don't all fit, show the chevron (unless suppressed). |
| 276 int max_x = GetPreferredSize().width(); | 321 int max_x = GetPreferredSize().width(); |
| 277 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_) { | 322 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) { |
| 278 chevron_->SetVisible(true); | 323 chevron_->SetVisible(true); |
| 279 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 324 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
| 280 max_x -= | 325 max_x -= |
| 281 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; | 326 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; |
| 282 chevron_->SetBounds( | 327 chevron_->SetBounds( |
| 283 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 328 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
| 284 0, | 329 0, |
| 285 chevron_size.width(), | 330 chevron_size.width(), |
| 286 chevron_size.height()); | 331 chevron_size.height()); |
| 287 } else { | 332 } else if (chevron_) { |
| 288 chevron_->SetVisible(false); | 333 chevron_->SetVisible(false); |
| 289 } | 334 } |
| 290 | 335 |
| 291 // Now draw the icons for the browser actions in the available space. | 336 // Now draw the icons for the browser actions in the available space. |
| 292 int icon_width = IconWidth(false); | 337 int icon_width = IconWidth(false); |
| 293 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 338 if (handling_overflow()) { |
| 294 BrowserActionView* view = browser_action_views_[i]; | 339 for (size_t i = 0; |
| 295 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | 340 i < main_container_->VisibleBrowserActionsAfterAnimation(); ++i) { |
| 296 if (x + icon_width <= max_x) { | 341 // Ensure that any browser actions shown in the main view are hidden in |
| 297 view->SetBounds(x, 0, icon_width, height()); | 342 // the overflow view. |
| 343 browser_action_views_[i]->SetVisible(false); | |
| 344 } | |
| 345 | |
| 346 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); | |
| 347 i < browser_action_views_.size(); ++i) { | |
| 348 BrowserActionView* view = browser_action_views_[i]; | |
| 349 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); | |
| 350 int x = ToolbarView::kStandardSpacing + index * IconWidth(true) - | |
| 351 ((index / kIconsPerMenuRow) * (IconWidth(true) * kIconsPerMenuRow)); | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Parens around "IconWidth(true) * kIconsPerMen
Finnur
2014/07/02 16:59:56
Done.
| |
| 352 gfx::Rect rect_bounds( | |
| 353 x, | |
| 354 IconHeight() * (static_cast<int>(index) / kIconsPerMenuRow), | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: You compute this quotient twice, consider usi
Finnur
2014/07/02 16:59:55
Done.
| |
| 355 icon_width, | |
| 356 IconHeight() + kPaddingForBadge); | |
| 357 view->SetBoundsRect(rect_bounds); | |
| 298 view->SetVisible(true); | 358 view->SetVisible(true); |
| 299 } else { | 359 } |
| 300 view->SetVisible(false); | 360 } else { |
| 361 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Use an iterator
Finnur
2014/07/02 16:59:56
Done.
| |
| 362 BrowserActionView* view = browser_action_views_[i]; | |
| 363 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | |
| 364 if (x + icon_width <= max_x) { | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Simpler:
view->SetVisible(x + icon_wid
Finnur
2014/07/02 16:59:56
Done.
| |
| 365 view->SetBounds(x, 0, icon_width, IconHeight()); | |
| 366 view->SetVisible(true); | |
| 367 } else { | |
| 368 view->SetVisible(false); | |
| 369 } | |
| 301 } | 370 } |
| 302 } | 371 } |
| 303 } | 372 } |
| 304 | 373 |
| 305 bool BrowserActionsContainer::GetDropFormats( | 374 bool BrowserActionsContainer::GetDropFormats( |
| 306 int* formats, | 375 int* formats, |
| 307 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 376 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
| 308 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); | 377 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); |
| 309 | 378 |
| 310 return true; | 379 return true; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 326 int BrowserActionsContainer::OnDragUpdated( | 395 int BrowserActionsContainer::OnDragUpdated( |
| 327 const ui::DropTargetEvent& event) { | 396 const ui::DropTargetEvent& event) { |
| 328 // First check if we are above the chevron (overflow) menu. | 397 // First check if we are above the chevron (overflow) menu. |
| 329 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 398 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
| 330 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 399 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| 331 StartShowFolderDropMenuTimer(); | 400 StartShowFolderDropMenuTimer(); |
| 332 return ui::DragDropTypes::DRAG_MOVE; | 401 return ui::DragDropTypes::DRAG_MOVE; |
| 333 } | 402 } |
| 334 StopShowFolderDropMenuTimer(); | 403 StopShowFolderDropMenuTimer(); |
| 335 | 404 |
| 405 // TODO(devlin): This calculation needs to take 'overflow' mode into account | |
| 406 // once the wrench menu becomes a drag target for browser action icons. | |
| 407 | |
| 336 // Figure out where to display the indicator. This is a complex calculation: | 408 // Figure out where to display the indicator. This is a complex calculation: |
| 337 | 409 |
| 338 // First, we figure out how much space is to the left of the icon area, so we | 410 // First, we figure out how much space is to the left of the icon area, so we |
| 339 // can calculate the true offset into the icon area. | 411 // can calculate the true offset into the icon area. |
| 340 int width_before_icons = ToolbarView::kStandardSpacing + | 412 int width_before_icons = ToolbarView::kStandardSpacing; |
| 341 (base::i18n::IsRTL() ? | 413 if (chevron_ && base::i18n::IsRTL()) { |
| 342 (chevron_->GetPreferredSize().width() + kChevronSpacing) : 0); | 414 width_before_icons += |
| 415 chevron_->GetPreferredSize().width() + kChevronSpacing; | |
| 416 } | |
| 343 int offset_into_icon_area = event.x() - width_before_icons; | 417 int offset_into_icon_area = event.x() - width_before_icons; |
| 344 | 418 |
| 345 // Next, we determine which icon to place the indicator in front of. We want | 419 // Next, we determine which icon to place the indicator in front of. We want |
| 346 // to place the indicator in front of icon n when the cursor is between the | 420 // to place the indicator in front of icon n when the cursor is between the |
| 347 // midpoints of icons (n - 1) and n. To do this we take the offset into the | 421 // midpoints of icons (n - 1) and n. To do this we take the offset into the |
| 348 // icon area and transform it as follows: | 422 // icon area and transform it as follows: |
| 349 // | 423 // |
| 350 // Real icon area: | 424 // Real icon area: |
| 351 // 0 a * b c | 425 // 0 a * b c |
| 352 // | | | | | 426 // | | | | |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | 623 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); |
| 550 } | 624 } |
| 551 | 625 |
| 552 void BrowserActionsContainer::OnBrowserActionExecuted( | 626 void BrowserActionsContainer::OnBrowserActionExecuted( |
| 553 BrowserActionButton* button) { | 627 BrowserActionButton* button) { |
| 554 ShowPopup(button, ExtensionPopup::SHOW, true); | 628 ShowPopup(button, ExtensionPopup::SHOW, true); |
| 555 } | 629 } |
| 556 | 630 |
| 557 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 631 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 558 SetVisible(!browser_action_views_.empty()); | 632 SetVisible(!browser_action_views_.empty()); |
| 559 owner_view_->Layout(); | 633 if (owner_view_) { |
| 560 owner_view_->SchedulePaint(); | 634 owner_view_->Layout(); |
| 635 owner_view_->SchedulePaint(); | |
| 636 } | |
| 561 } | 637 } |
| 562 | 638 |
| 563 extensions::ActiveTabPermissionGranter* | 639 extensions::ActiveTabPermissionGranter* |
| 564 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 640 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 565 content::WebContents* web_contents = | 641 content::WebContents* web_contents = |
| 566 browser_->tab_strip_model()->GetActiveWebContents(); | 642 browser_->tab_strip_model()->GetActiveWebContents(); |
| 567 if (!web_contents) | 643 if (!web_contents) |
| 568 return NULL; | 644 return NULL; |
| 569 return extensions::TabHelper::FromWebContents(web_contents)-> | 645 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 570 active_tab_permission_granter(); | 646 active_tab_permission_granter(); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 | 834 |
| 759 if (browser_action_views_.size() > visible_actions) { | 835 if (browser_action_views_.size() > visible_actions) { |
| 760 // If we have more icons than we can show, then we must not be changing | 836 // If we have more icons than we can show, then we must not be changing |
| 761 // the container size (since we either removed an icon from the main | 837 // the container size (since we either removed an icon from the main |
| 762 // area and one from the overflow list will have shifted in, or we | 838 // area and one from the overflow list will have shifted in, or we |
| 763 // removed an entry directly from the overflow list). | 839 // removed an entry directly from the overflow list). |
| 764 OnBrowserActionVisibilityChanged(); | 840 OnBrowserActionVisibilityChanged(); |
| 765 } else { | 841 } else { |
| 766 // Either we went from overflow to no-overflow, or we shrunk the no- | 842 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 767 // overflow container by 1. Either way the size changed, so animate. | 843 // overflow container by 1. Either way the size changed, so animate. |
| 768 chevron_->SetVisible(false); | 844 if (chevron_) |
| 845 chevron_->SetVisible(false); | |
| 769 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, | 846 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, |
| 770 browser_action_views_.size()); | 847 browser_action_views_.size()); |
| 771 } | 848 } |
| 772 return; | 849 return; // We have found the action to remove, bail out. |
| 773 } | 850 } |
| 774 } | 851 } |
| 775 } | 852 } |
| 776 | 853 |
| 777 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, | 854 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, |
| 778 int index) { | 855 int index) { |
| 779 if (!ShouldDisplayBrowserAction(extension)) | 856 if (!ShouldDisplayBrowserAction(extension)) |
| 780 return; | 857 return; |
| 781 | 858 |
| 782 if (profile_->IsOffTheRecord()) | 859 if (profile_->IsOffTheRecord()) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 804 // we delete and recreate everything here, but that's how it's done in | 881 // we delete and recreate everything here, but that's how it's done in |
| 805 // BrowserActionMoved(), too. If we want to optimize it, we could move the | 882 // BrowserActionMoved(), too. If we want to optimize it, we could move the |
| 806 // existing icons, instead of deleting it all. | 883 // existing icons, instead of deleting it all. |
| 807 DeleteBrowserActionViews(); | 884 DeleteBrowserActionViews(); |
| 808 CreateBrowserActionViews(); | 885 CreateBrowserActionViews(); |
| 809 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); | 886 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); |
| 810 } | 887 } |
| 811 | 888 |
| 812 void BrowserActionsContainer::LoadImages() { | 889 void BrowserActionsContainer::LoadImages() { |
| 813 ui::ThemeProvider* tp = GetThemeProvider(); | 890 ui::ThemeProvider* tp = GetThemeProvider(); |
| 891 if (!tp || !chevron_) | |
| 892 return; | |
| 893 | |
| 814 chevron_->SetImage(views::Button::STATE_NORMAL, | 894 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 815 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 895 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
| 816 | 896 |
| 817 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 897 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 818 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 898 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 819 } | 899 } |
| 820 | 900 |
| 821 void BrowserActionsContainer::SetContainerWidth() { | 901 void BrowserActionsContainer::SetContainerWidth() { |
| 822 int visible_actions = model_->GetVisibleIconCount(); | 902 // The slave only draws the overflow (what isn't visible in the other |
| 903 // container). | |
| 904 int visible_actions = handling_overflow() ? model_->toolbar_items().size() - | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Break after '?' instead of before ':' and ind
Finnur
2014/07/02 16:59:56
Done.
| |
| 905 model_->GetVisibleIconCount() | |
| 906 : model_->GetVisibleIconCount(); | |
| 823 if (visible_actions < 0) // All icons should be visible. | 907 if (visible_actions < 0) // All icons should be visible. |
| 824 visible_actions = model_->toolbar_items().size(); | 908 visible_actions = model_->toolbar_items().size(); |
| 825 chevron_->SetVisible( | 909 if (chevron_) { |
| 826 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); | 910 chevron_->SetVisible( |
| 827 container_width_ = IconCountToWidth(visible_actions, chevron_->visible()); | 911 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); |
| 912 } | |
| 913 container_width_ = | |
| 914 IconCountToWidth(visible_actions, chevron_ ? chevron_->visible() : false); | |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Simpler: chevron_ && chevron_->visible()
Finnur
2014/07/02 16:59:56
Done.
| |
| 828 } | 915 } |
| 829 | 916 |
| 830 void BrowserActionsContainer::CloseOverflowMenu() { | 917 void BrowserActionsContainer::CloseOverflowMenu() { |
| 831 if (overflow_menu_) | 918 if (overflow_menu_) |
| 832 overflow_menu_->CancelMenu(); | 919 overflow_menu_->CancelMenu(); |
| 833 } | 920 } |
| 834 | 921 |
| 835 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 922 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
| 836 show_menu_task_factory_.InvalidateWeakPtrs(); | 923 show_menu_task_factory_.InvalidateWeakPtrs(); |
| 837 } | 924 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 861 } | 948 } |
| 862 | 949 |
| 863 int BrowserActionsContainer::IconCountToWidth(int icons, | 950 int BrowserActionsContainer::IconCountToWidth(int icons, |
| 864 bool display_chevron) const { | 951 bool display_chevron) const { |
| 865 if (icons < 0) | 952 if (icons < 0) |
| 866 icons = browser_action_views_.size(); | 953 icons = browser_action_views_.size(); |
| 867 if ((icons == 0) && !display_chevron) | 954 if ((icons == 0) && !display_chevron) |
| 868 return ToolbarView::kStandardSpacing; | 955 return ToolbarView::kStandardSpacing; |
| 869 int icons_size = | 956 int icons_size = |
| 870 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 957 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
| 871 int chevron_size = display_chevron ? | 958 int chevron_size = chevron_ && display_chevron ? |
| 872 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 959 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| 873 return ToolbarView::kStandardSpacing + icons_size + chevron_size + | 960 return ToolbarView::kStandardSpacing + icons_size + chevron_size + |
| 874 ToolbarView::kStandardSpacing; | 961 ToolbarView::kStandardSpacing; |
| 875 } | 962 } |
| 876 | 963 |
| 877 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 964 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
| 878 // Check for widths large enough to show the entire icon set. | 965 // Check for widths large enough to show the entire icon set. |
| 879 if (pixels >= IconCountToWidth(-1, false)) | 966 if (pixels >= IconCountToWidth(-1, false)) |
| 880 return browser_action_views_.size(); | 967 return browser_action_views_.size(); |
| 881 | 968 |
| 882 // We need to reserve space for the resize area, chevron, and the spacing on | 969 // We need to reserve space for the resize area, chevron, and the spacing on |
| 883 // either side of the chevron. | 970 // either side of the chevron. |
| 884 int available_space = pixels - ToolbarView::kStandardSpacing - | 971 int available_space = pixels - ToolbarView::kStandardSpacing - |
| 885 chevron_->GetPreferredSize().width() - kChevronSpacing - | 972 (chevron_ ? chevron_->GetPreferredSize().width() : 0) - |
| 886 ToolbarView::kStandardSpacing; | 973 kChevronSpacing - ToolbarView::kStandardSpacing; |
| 887 // Now we add an extra between-item padding value so the space can be divided | 974 // Now we add an extra between-item padding value so the space can be divided |
| 888 // evenly by (size of icon with padding). | 975 // evenly by (size of icon with padding). |
| 889 return static_cast<size_t>( | 976 return static_cast<size_t>( |
| 890 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 977 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
| 891 } | 978 } |
| 892 | 979 |
| 893 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 980 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
| 894 return ToolbarView::kStandardSpacing + kChevronSpacing + | 981 return ToolbarView::kStandardSpacing + |
| 895 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; | 982 (chevron_ ? (kChevronSpacing + chevron_->GetPreferredSize().width() + |
|
Peter Kasting
2014/06/30 23:36:33
Nit: Unusual indenting/wrapping; how about this:
Finnur
2014/07/02 16:59:56
Done.
| |
| 983 ToolbarView::kStandardSpacing) | |
| 984 : 0); | |
| 896 } | 985 } |
| 897 | 986 |
| 898 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 987 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
| 899 gfx::Tween::Type tween_type, | 988 gfx::Tween::Type tween_type, |
| 900 size_t num_visible_icons) { | 989 size_t num_visible_icons) { |
| 901 // Save off the desired number of visible icons. We do this now instead of at | 990 // Save off the desired number of visible icons. We do this now instead of at |
| 902 // the end of the animation so that even if the browser is shut down while | 991 // the end of the animation so that even if the browser is shut down while |
| 903 // animating, the right value will be restored on next run. | 992 // animating, the right value will be restored on next run. |
| 904 // NOTE: Don't save the icon count in incognito because there may be fewer | 993 // NOTE: Don't save the icon count in incognito because there may be fewer |
| 905 // icons in that mode. The result is that the container in a normal window is | 994 // icons in that mode. The result is that the container in a normal window is |
| 906 // always at least as wide as in an incognito window. | 995 // always at least as wide as in an incognito window. |
| 907 if (!profile_->IsOffTheRecord()) | 996 if (!profile_->IsOffTheRecord()) |
| 908 model_->SetVisibleIconCount(num_visible_icons); | 997 model_->SetVisibleIconCount(num_visible_icons); |
| 909 int target_size = IconCountToWidth(num_visible_icons, | 998 int target_size = IconCountToWidth(num_visible_icons, |
| 910 num_visible_icons < browser_action_views_.size()); | 999 num_visible_icons < browser_action_views_.size()); |
| 911 if (!disable_animations_during_testing_) { | 1000 if (resize_animation_ && !disable_animations_during_testing_) { |
| 912 // Animate! We have to set the animation_target_size_ after calling Reset(), | 1001 // Animate! We have to set the animation_target_size_ after calling Reset(), |
| 913 // because that could end up calling AnimationEnded which clears the value. | 1002 // because that could end up calling AnimationEnded which clears the value. |
| 914 resize_animation_->Reset(); | 1003 resize_animation_->Reset(); |
| 915 resize_animation_->SetTweenType(tween_type); | 1004 resize_animation_->SetTweenType(tween_type); |
| 916 animation_target_size_ = target_size; | 1005 animation_target_size_ = target_size; |
| 917 resize_animation_->Show(); | 1006 resize_animation_->Show(); |
| 918 } else { | 1007 } else { |
| 919 animation_target_size_ = target_size; | 1008 animation_target_size_ = target_size; |
| 920 AnimationEnded(resize_animation_.get()); | 1009 AnimationEnded(resize_animation_.get()); |
| 921 } | 1010 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 views::BubbleBorder::TOP_RIGHT, | 1047 views::BubbleBorder::TOP_RIGHT, |
| 959 show_action); | 1048 show_action); |
| 960 popup_->GetWidget()->AddObserver(this); | 1049 popup_->GetWidget()->AddObserver(this); |
| 961 popup_button_ = button; | 1050 popup_button_ = button; |
| 962 | 1051 |
| 963 // Only set button as pushed if it was triggered by a user click. | 1052 // Only set button as pushed if it was triggered by a user click. |
| 964 if (should_grant) | 1053 if (should_grant) |
| 965 popup_button_->SetButtonPushed(); | 1054 popup_button_->SetButtonPushed(); |
| 966 return true; | 1055 return true; |
| 967 } | 1056 } |
| OLD | NEW |