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). | |
63 const int kPaddingForBadge = 9; | |
64 | |
65 // The maximum number of icons to show per row when in overflow mode (showing | |
66 // icons in the application menu). | |
67 const int kIconsPerMenuRow = 7; | |
68 | |
60 // A version of MenuButton with almost empty insets to fit properly on the | 69 // A version of MenuButton with almost empty insets to fit properly on the |
61 // toolbar. | 70 // toolbar. |
62 class ChevronMenuButton : public views::MenuButton { | 71 class ChevronMenuButton : public views::MenuButton { |
63 public: | 72 public: |
64 ChevronMenuButton(views::ButtonListener* listener, | 73 ChevronMenuButton(views::ButtonListener* listener, |
65 const base::string16& text, | 74 const base::string16& text, |
66 views::MenuButtonListener* menu_button_listener, | 75 views::MenuButtonListener* menu_button_listener, |
67 bool show_menu_marker) | 76 bool show_menu_marker) |
68 : views::MenuButton(listener, | 77 : views::MenuButton(listener, |
69 text, | 78 text, |
(...skipping 17 matching lines...) Expand all Loading... | |
87 }; | 96 }; |
88 | 97 |
89 } // namespace | 98 } // namespace |
90 | 99 |
91 // static | 100 // static |
92 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 101 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
93 | 102 |
94 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
95 // BrowserActionsContainer | 104 // BrowserActionsContainer |
96 | 105 |
97 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, | 106 BrowserActionsContainer::BrowserActionsContainer( |
98 View* owner_view) | 107 Browser* browser, View* owner_view, BrowserActionsContainer* main_container) |
99 : profile_(browser->profile()), | 108 : profile_(browser->profile()), |
100 browser_(browser), | 109 browser_(browser), |
101 owner_view_(owner_view), | 110 owner_view_(owner_view), |
111 main_container_(main_container), | |
102 popup_(NULL), | 112 popup_(NULL), |
103 popup_button_(NULL), | 113 popup_button_(NULL), |
104 model_(NULL), | 114 model_(NULL), |
105 container_width_(0), | 115 container_width_(0), |
116 resize_area_(NULL), | |
106 chevron_(NULL), | 117 chevron_(NULL), |
107 overflow_menu_(NULL), | 118 overflow_menu_(NULL), |
108 suppress_chevron_(false), | 119 suppress_chevron_(false), |
109 resize_amount_(0), | 120 resize_amount_(0), |
110 animation_target_size_(0), | 121 animation_target_size_(0), |
111 drop_indicator_position_(-1), | 122 drop_indicator_position_(-1), |
112 task_factory_(this), | 123 task_factory_(this), |
113 show_menu_task_factory_(this) { | 124 show_menu_task_factory_(this) { |
114 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 125 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
115 | 126 |
116 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 127 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
117 if (model_) | 128 if (model_) |
118 model_->AddObserver(this); | 129 model_->AddObserver(this); |
119 | 130 |
120 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 131 bool overflow_experiment = |
121 browser->profile(), | 132 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
122 owner_view->GetFocusManager(), | 133 DCHECK(!handling_overflow() || overflow_experiment); |
123 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | |
124 this)); | |
125 | 134 |
126 resize_animation_.reset(new gfx::SlideAnimation(this)); | 135 if (!handling_overflow()) { |
127 resize_area_ = new views::ResizeArea(this); | 136 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
128 AddChildView(resize_area_); | 137 browser->profile(), |
138 owner_view->GetFocusManager(), | |
139 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | |
140 this)); | |
129 | 141 |
130 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | 142 resize_animation_.reset(new gfx::SlideAnimation(this)); |
131 chevron_->EnableCanvasFlippingForRTLUI(true); | 143 resize_area_ = new views::ResizeArea(this); |
132 chevron_->SetAccessibleName( | 144 AddChildView(resize_area_); |
133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 145 |
134 chevron_->SetVisible(false); | 146 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside |
135 AddChildView(chevron_); | 147 // the hamburger menu. |
148 if (!overflow_experiment) { | |
149 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | |
150 chevron_->SetBorder(views::Border::NullBorder()); | |
151 chevron_->EnableCanvasFlippingForRTLUI(true); | |
152 chevron_->SetAccessibleName( | |
153 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | |
154 chevron_->SetVisible(false); | |
155 AddChildView(chevron_); | |
156 } | |
157 } | |
136 } | 158 } |
137 | 159 |
138 BrowserActionsContainer::~BrowserActionsContainer() { | 160 BrowserActionsContainer::~BrowserActionsContainer() { |
139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 161 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
140 observers_, | 162 observers_, |
141 OnBrowserActionsContainerDestroyed()); | 163 OnBrowserActionsContainerDestroyed()); |
142 | 164 |
143 if (overflow_menu_) | 165 if (overflow_menu_) |
144 overflow_menu_->set_observer(NULL); | 166 overflow_menu_->set_observer(NULL); |
145 if (model_) | 167 if (model_) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 void BrowserActionsContainer::ExecuteExtensionCommand( | 248 void BrowserActionsContainer::ExecuteExtensionCommand( |
227 const extensions::Extension* extension, | 249 const extensions::Extension* extension, |
228 const extensions::Command& command) { | 250 const extensions::Command& command) { |
229 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 251 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
230 // instance. | 252 // instance. |
231 DCHECK(!command.global()); | 253 DCHECK(!command.global()); |
232 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 254 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
233 command.accelerator()); | 255 command.accelerator()); |
234 } | 256 } |
235 | 257 |
258 bool BrowserActionsContainer::ShownInsideMenu() const { | |
259 return handling_overflow(); | |
260 } | |
261 | |
236 void BrowserActionsContainer::AddObserver( | 262 void BrowserActionsContainer::AddObserver( |
237 BrowserActionsContainerObserver* observer) { | 263 BrowserActionsContainerObserver* observer) { |
238 observers_.AddObserver(observer); | 264 observers_.AddObserver(observer); |
239 } | 265 } |
240 | 266 |
241 void BrowserActionsContainer::RemoveObserver( | 267 void BrowserActionsContainer::RemoveObserver( |
242 BrowserActionsContainerObserver* observer) { | 268 BrowserActionsContainerObserver* observer) { |
243 observers_.RemoveObserver(observer); | 269 observers_.RemoveObserver(observer); |
244 } | 270 } |
245 | 271 |
246 gfx::Size BrowserActionsContainer::GetPreferredSize() const { | 272 gfx::Size BrowserActionsContainer::GetPreferredSize() const { |
273 size_t our_icon_count = browser_action_views_.size() - | |
274 (handling_overflow() ? main_container_->VisibleBrowserActions() : 0); | |
275 | |
276 // If there are no actions to show, or we are in overflow mode and the main | |
277 // container is already showing them all, then no further work is required. | |
278 if (our_icon_count == 0) | |
279 return gfx::Size(); | |
280 | |
281 if (handling_overflow()) { | |
282 // When in overflow, y is multiline, so the pixel count is IconHeight() | |
283 // times the number of rows need. | |
Devlin
2014/06/26 16:29:13
nit: s/need/needed.
Finnur
2014/06/27 14:23:38
Done.
| |
284 return gfx::Size( | |
285 IconCountToWidth(kIconsPerMenuRow, false), | |
286 (((our_icon_count - 1) / kIconsPerMenuRow) + 1) * IconHeight()); | |
287 } | |
288 | |
247 // We calculate the size of the view by taking the current width and | 289 // 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 | 290 // 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). | 291 // 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 | 292 // 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 | 293 // container can never shrink too far or take up more space than it needs. |
252 // other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). | 294 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). |
253 int preferred_width = std::min( | 295 int preferred_width = std::min( |
254 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), | 296 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), |
255 IconCountToWidth(-1, false)); | 297 IconCountToWidth(-1, false)); |
256 // Height will be ignored by the ToolbarView. | 298 return gfx::Size(preferred_width, IconHeight()); |
257 return gfx::Size(preferred_width, 0); | |
258 } | 299 } |
259 | 300 |
260 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 301 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
261 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); | 302 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); |
262 // Height will be ignored by the ToolbarView. | 303 return gfx::Size(min_width, IconHeight()); |
263 return gfx::Size(min_width, 0); | |
264 } | 304 } |
265 | 305 |
266 void BrowserActionsContainer::Layout() { | 306 void BrowserActionsContainer::Layout() { |
267 if (browser_action_views_.empty()) { | 307 if (browser_action_views_.empty()) { |
268 SetVisible(false); | 308 SetVisible(false); |
269 return; | 309 return; |
270 } | 310 } |
271 | 311 |
272 SetVisible(true); | 312 SetVisible(true); |
273 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 313 if (resize_area_) |
314 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | |
274 | 315 |
275 // If the icons don't all fit, show the chevron (unless suppressed). | 316 // If the icons don't all fit, show the chevron (unless suppressed). |
276 int max_x = GetPreferredSize().width(); | 317 int max_x = GetPreferredSize().width(); |
277 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_) { | 318 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) { |
278 chevron_->SetVisible(true); | 319 chevron_->SetVisible(true); |
279 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 320 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
280 max_x -= | 321 max_x -= |
281 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; | 322 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; |
282 chevron_->SetBounds( | 323 chevron_->SetBounds( |
283 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 324 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
284 0, | 325 0, |
285 chevron_size.width(), | 326 chevron_size.width(), |
286 chevron_size.height()); | 327 chevron_size.height()); |
287 } else { | 328 } else if (chevron_) { |
288 chevron_->SetVisible(false); | 329 chevron_->SetVisible(false); |
289 } | 330 } |
290 | 331 |
291 // Now draw the icons for the browser actions in the available space. | 332 // Now draw the icons for the browser actions in the available space. |
292 int icon_width = IconWidth(false); | 333 int icon_width = IconWidth(false); |
293 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 334 if (handling_overflow()) { |
294 BrowserActionView* view = browser_action_views_[i]; | 335 for (size_t i = main_container_->VisibleBrowserActionsAfterAnimation(); |
295 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | 336 i < browser_action_views_.size(); ++i) { |
296 if (x + icon_width <= max_x) { | 337 BrowserActionView* view = |
297 view->SetBounds(x, 0, icon_width, height()); | 338 browser_action_views_[i]; |
Devlin
2014/06/26 16:29:13
nit: I think this can go on the previous line now.
Finnur
2014/06/27 14:23:38
Done.
| |
339 size_t index = i - main_container_->VisibleBrowserActionsAfterAnimation(); | |
340 int x = ToolbarView::kStandardSpacing + index * IconWidth(true) - | |
341 ((index / kIconsPerMenuRow) * (IconWidth(true) * kIconsPerMenuRow)); | |
342 gfx::Rect rect_bounds( | |
343 x, | |
344 IconHeight() * (static_cast<int>(index) / kIconsPerMenuRow), | |
345 icon_width, | |
346 IconHeight() + kPaddingForBadge); | |
347 view->SetBoundsRect(rect_bounds); | |
298 view->SetVisible(true); | 348 view->SetVisible(true); |
299 } else { | 349 } |
300 view->SetVisible(false); | 350 } else { |
351 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | |
352 BrowserActionView* view = browser_action_views_[i]; | |
353 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | |
354 if (x + icon_width <= max_x) { | |
355 view->SetBounds(x, 0, icon_width, IconHeight()); | |
356 view->SetVisible(true); | |
357 } else { | |
358 view->SetVisible(false); | |
359 } | |
301 } | 360 } |
302 } | 361 } |
303 } | 362 } |
304 | 363 |
305 bool BrowserActionsContainer::GetDropFormats( | 364 bool BrowserActionsContainer::GetDropFormats( |
306 int* formats, | 365 int* formats, |
307 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 366 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
308 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); | 367 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); |
309 | 368 |
310 return true; | 369 return true; |
(...skipping 15 matching lines...) Expand all Loading... | |
326 int BrowserActionsContainer::OnDragUpdated( | 385 int BrowserActionsContainer::OnDragUpdated( |
327 const ui::DropTargetEvent& event) { | 386 const ui::DropTargetEvent& event) { |
328 // First check if we are above the chevron (overflow) menu. | 387 // First check if we are above the chevron (overflow) menu. |
329 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 388 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
330 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 389 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
331 StartShowFolderDropMenuTimer(); | 390 StartShowFolderDropMenuTimer(); |
332 return ui::DragDropTypes::DRAG_MOVE; | 391 return ui::DragDropTypes::DRAG_MOVE; |
333 } | 392 } |
334 StopShowFolderDropMenuTimer(); | 393 StopShowFolderDropMenuTimer(); |
335 | 394 |
395 // TODO(finnur): This calculation needs to take 'overflow' mode into account | |
396 // once the wrench menu becomes a drag target for browser action icons. | |
397 | |
336 // Figure out where to display the indicator. This is a complex calculation: | 398 // Figure out where to display the indicator. This is a complex calculation: |
337 | 399 |
338 // First, we figure out how much space is to the left of the icon area, so we | 400 // 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. | 401 // can calculate the true offset into the icon area. |
340 int width_before_icons = ToolbarView::kStandardSpacing + | 402 int width_before_icons = ToolbarView::kStandardSpacing; |
341 (base::i18n::IsRTL() ? | 403 if (chevron_ && base::i18n::IsRTL()) { |
342 (chevron_->GetPreferredSize().width() + kChevronSpacing) : 0); | 404 width_before_icons += |
405 chevron_->GetPreferredSize().width() + kChevronSpacing; | |
406 } | |
343 int offset_into_icon_area = event.x() - width_before_icons; | 407 int offset_into_icon_area = event.x() - width_before_icons; |
344 | 408 |
345 // Next, we determine which icon to place the indicator in front of. We want | 409 // 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 | 410 // 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 | 411 // midpoints of icons (n - 1) and n. To do this we take the offset into the |
348 // icon area and transform it as follows: | 412 // icon area and transform it as follows: |
349 // | 413 // |
350 // Real icon area: | 414 // Real icon area: |
351 // 0 a * b c | 415 // 0 a * b c |
352 // | | | | | 416 // | | | | |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | 613 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); |
550 } | 614 } |
551 | 615 |
552 void BrowserActionsContainer::OnBrowserActionExecuted( | 616 void BrowserActionsContainer::OnBrowserActionExecuted( |
553 BrowserActionButton* button) { | 617 BrowserActionButton* button) { |
554 ShowPopup(button, ExtensionPopup::SHOW, true); | 618 ShowPopup(button, ExtensionPopup::SHOW, true); |
555 } | 619 } |
556 | 620 |
557 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 621 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
558 SetVisible(!browser_action_views_.empty()); | 622 SetVisible(!browser_action_views_.empty()); |
559 owner_view_->Layout(); | 623 if (owner_view_) { |
560 owner_view_->SchedulePaint(); | 624 owner_view_->Layout(); |
625 owner_view_->SchedulePaint(); | |
626 } | |
561 } | 627 } |
562 | 628 |
563 extensions::ActiveTabPermissionGranter* | 629 extensions::ActiveTabPermissionGranter* |
564 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 630 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
565 content::WebContents* web_contents = | 631 content::WebContents* web_contents = |
566 browser_->tab_strip_model()->GetActiveWebContents(); | 632 browser_->tab_strip_model()->GetActiveWebContents(); |
567 if (!web_contents) | 633 if (!web_contents) |
568 return NULL; | 634 return NULL; |
569 return extensions::TabHelper::FromWebContents(web_contents)-> | 635 return extensions::TabHelper::FromWebContents(web_contents)-> |
570 active_tab_permission_granter(); | 636 active_tab_permission_granter(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 | 824 |
759 if (browser_action_views_.size() > visible_actions) { | 825 if (browser_action_views_.size() > visible_actions) { |
760 // If we have more icons than we can show, then we must not be changing | 826 // 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 | 827 // 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 | 828 // area and one from the overflow list will have shifted in, or we |
763 // removed an entry directly from the overflow list). | 829 // removed an entry directly from the overflow list). |
764 OnBrowserActionVisibilityChanged(); | 830 OnBrowserActionVisibilityChanged(); |
765 } else { | 831 } else { |
766 // Either we went from overflow to no-overflow, or we shrunk the no- | 832 // 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. | 833 // overflow container by 1. Either way the size changed, so animate. |
768 chevron_->SetVisible(false); | 834 if (chevron_) |
835 chevron_->SetVisible(false); | |
769 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, | 836 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, |
770 browser_action_views_.size()); | 837 browser_action_views_.size()); |
771 } | 838 } |
772 return; | 839 return; // We have found the action to remove, bail out. |
773 } | 840 } |
774 } | 841 } |
775 } | 842 } |
776 | 843 |
777 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, | 844 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, |
778 int index) { | 845 int index) { |
779 if (!ShouldDisplayBrowserAction(extension)) | 846 if (!ShouldDisplayBrowserAction(extension)) |
780 return; | 847 return; |
781 | 848 |
782 if (profile_->IsOffTheRecord()) | 849 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 | 871 // 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 | 872 // BrowserActionMoved(), too. If we want to optimize it, we could move the |
806 // existing icons, instead of deleting it all. | 873 // existing icons, instead of deleting it all. |
807 DeleteBrowserActionViews(); | 874 DeleteBrowserActionViews(); |
808 CreateBrowserActionViews(); | 875 CreateBrowserActionViews(); |
809 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); | 876 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); |
810 } | 877 } |
811 | 878 |
812 void BrowserActionsContainer::LoadImages() { | 879 void BrowserActionsContainer::LoadImages() { |
813 ui::ThemeProvider* tp = GetThemeProvider(); | 880 ui::ThemeProvider* tp = GetThemeProvider(); |
881 if (!tp || !chevron_) | |
882 return; | |
883 | |
814 chevron_->SetImage(views::Button::STATE_NORMAL, | 884 chevron_->SetImage(views::Button::STATE_NORMAL, |
815 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 885 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
816 | 886 |
817 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 887 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
818 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 888 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
819 } | 889 } |
820 | 890 |
821 void BrowserActionsContainer::SetContainerWidth() { | 891 void BrowserActionsContainer::SetContainerWidth() { |
822 int visible_actions = model_->GetVisibleIconCount(); | 892 // The slave only draws the overflow (what isn't visible in the other |
893 // container). | |
894 int visible_actions = handling_overflow() ? model_->toolbar_items().size() - | |
895 model_->GetVisibleIconCount() | |
896 : model_->GetVisibleIconCount(); | |
823 if (visible_actions < 0) // All icons should be visible. | 897 if (visible_actions < 0) // All icons should be visible. |
824 visible_actions = model_->toolbar_items().size(); | 898 visible_actions = model_->toolbar_items().size(); |
825 chevron_->SetVisible( | 899 if (chevron_) { |
826 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); | 900 chevron_->SetVisible( |
827 container_width_ = IconCountToWidth(visible_actions, chevron_->visible()); | 901 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); |
902 } | |
903 container_width_ = | |
904 IconCountToWidth(visible_actions, chevron_ ? chevron_->visible() : false); | |
828 } | 905 } |
829 | 906 |
830 void BrowserActionsContainer::CloseOverflowMenu() { | 907 void BrowserActionsContainer::CloseOverflowMenu() { |
831 if (overflow_menu_) | 908 if (overflow_menu_) |
832 overflow_menu_->CancelMenu(); | 909 overflow_menu_->CancelMenu(); |
833 } | 910 } |
834 | 911 |
835 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 912 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
836 show_menu_task_factory_.InvalidateWeakPtrs(); | 913 show_menu_task_factory_.InvalidateWeakPtrs(); |
837 } | 914 } |
(...skipping 23 matching lines...) Expand all Loading... | |
861 } | 938 } |
862 | 939 |
863 int BrowserActionsContainer::IconCountToWidth(int icons, | 940 int BrowserActionsContainer::IconCountToWidth(int icons, |
864 bool display_chevron) const { | 941 bool display_chevron) const { |
865 if (icons < 0) | 942 if (icons < 0) |
866 icons = browser_action_views_.size(); | 943 icons = browser_action_views_.size(); |
867 if ((icons == 0) && !display_chevron) | 944 if ((icons == 0) && !display_chevron) |
868 return ToolbarView::kStandardSpacing; | 945 return ToolbarView::kStandardSpacing; |
869 int icons_size = | 946 int icons_size = |
870 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 947 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
871 int chevron_size = display_chevron ? | 948 int chevron_size = chevron_ && display_chevron ? |
872 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 949 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
873 return ToolbarView::kStandardSpacing + icons_size + chevron_size + | 950 return ToolbarView::kStandardSpacing + icons_size + chevron_size + |
874 ToolbarView::kStandardSpacing; | 951 ToolbarView::kStandardSpacing; |
875 } | 952 } |
876 | 953 |
877 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 954 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
878 // Check for widths large enough to show the entire icon set. | 955 // Check for widths large enough to show the entire icon set. |
879 if (pixels >= IconCountToWidth(-1, false)) | 956 if (pixels >= IconCountToWidth(-1, false)) |
880 return browser_action_views_.size(); | 957 return browser_action_views_.size(); |
881 | 958 |
882 // We need to reserve space for the resize area, chevron, and the spacing on | 959 // We need to reserve space for the resize area, chevron, and the spacing on |
883 // either side of the chevron. | 960 // either side of the chevron. |
884 int available_space = pixels - ToolbarView::kStandardSpacing - | 961 int available_space = pixels - ToolbarView::kStandardSpacing - |
885 chevron_->GetPreferredSize().width() - kChevronSpacing - | 962 (chevron_ ? chevron_->GetPreferredSize().width() : 0) - |
886 ToolbarView::kStandardSpacing; | 963 kChevronSpacing - ToolbarView::kStandardSpacing; |
887 // Now we add an extra between-item padding value so the space can be divided | 964 // Now we add an extra between-item padding value so the space can be divided |
888 // evenly by (size of icon with padding). | 965 // evenly by (size of icon with padding). |
889 return static_cast<size_t>( | 966 return static_cast<size_t>( |
890 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 967 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
891 } | 968 } |
892 | 969 |
893 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 970 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
894 return ToolbarView::kStandardSpacing + kChevronSpacing + | 971 return ToolbarView::kStandardSpacing + |
895 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; | 972 (chevron_ ? (kChevronSpacing + chevron_->GetPreferredSize().width() + |
973 ToolbarView::kStandardSpacing) | |
974 : 0); | |
896 } | 975 } |
897 | 976 |
898 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 977 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
899 gfx::Tween::Type tween_type, | 978 gfx::Tween::Type tween_type, |
900 size_t num_visible_icons) { | 979 size_t num_visible_icons) { |
901 // Save off the desired number of visible icons. We do this now instead of at | 980 // 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 | 981 // 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. | 982 // 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 | 983 // 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 | 984 // 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. | 985 // always at least as wide as in an incognito window. |
907 if (!profile_->IsOffTheRecord()) | 986 if (!profile_->IsOffTheRecord()) |
908 model_->SetVisibleIconCount(num_visible_icons); | 987 model_->SetVisibleIconCount(num_visible_icons); |
909 int target_size = IconCountToWidth(num_visible_icons, | 988 int target_size = IconCountToWidth(num_visible_icons, |
910 num_visible_icons < browser_action_views_.size()); | 989 num_visible_icons < browser_action_views_.size()); |
911 if (!disable_animations_during_testing_) { | 990 if (resize_animation_ && !disable_animations_during_testing_) { |
912 // Animate! We have to set the animation_target_size_ after calling Reset(), | 991 // Animate! We have to set the animation_target_size_ after calling Reset(), |
913 // because that could end up calling AnimationEnded which clears the value. | 992 // because that could end up calling AnimationEnded which clears the value. |
914 resize_animation_->Reset(); | 993 resize_animation_->Reset(); |
915 resize_animation_->SetTweenType(tween_type); | 994 resize_animation_->SetTweenType(tween_type); |
916 animation_target_size_ = target_size; | 995 animation_target_size_ = target_size; |
917 resize_animation_->Show(); | 996 resize_animation_->Show(); |
918 } else { | 997 } else { |
919 animation_target_size_ = target_size; | 998 animation_target_size_ = target_size; |
920 AnimationEnded(resize_animation_.get()); | 999 AnimationEnded(resize_animation_.get()); |
921 } | 1000 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
958 views::BubbleBorder::TOP_RIGHT, | 1037 views::BubbleBorder::TOP_RIGHT, |
959 show_action); | 1038 show_action); |
960 popup_->GetWidget()->AddObserver(this); | 1039 popup_->GetWidget()->AddObserver(this); |
961 popup_button_ = button; | 1040 popup_button_ = button; |
962 | 1041 |
963 // Only set button as pushed if it was triggered by a user click. | 1042 // Only set button as pushed if it was triggered by a user click. |
964 if (should_grant) | 1043 if (should_grant) |
965 popup_button_->SetButtonPushed(); | 1044 popup_button_->SetButtonPushed(); |
966 return true; | 1045 return true; |
967 } | 1046 } |
OLD | NEW |