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