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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 AnimationEnded(resize_animation_.get()); | 298 AnimationEnded(resize_animation_.get()); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 void BrowserActionsContainer::SetChevronVisibility(bool visible) { | 302 void BrowserActionsContainer::SetChevronVisibility(bool visible) { |
303 if (chevron_) | 303 if (chevron_) |
304 chevron_->SetVisible(visible); | 304 chevron_->SetVisible(visible); |
305 } | 305 } |
306 | 306 |
307 int BrowserActionsContainer::GetWidth() const { | 307 int BrowserActionsContainer::GetWidth() const { |
308 return container_width_; | 308 return width(); |
309 } | 309 } |
310 | 310 |
311 bool BrowserActionsContainer::IsAnimating() const { | 311 bool BrowserActionsContainer::IsAnimating() const { |
312 return animating(); | 312 return animating(); |
313 } | 313 } |
314 | 314 |
315 void BrowserActionsContainer::StopAnimating() { | 315 void BrowserActionsContainer::StopAnimating() { |
316 animation_target_size_ = container_width_; | 316 animation_target_size_ = container_width_; |
317 resize_animation_->Reset(); | 317 resize_animation_->Reset(); |
318 } | 318 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 | 400 |
401 if (toolbar_action_views_.empty()) { | 401 if (toolbar_action_views_.empty()) { |
402 SetVisible(false); | 402 SetVisible(false); |
403 return; | 403 return; |
404 } | 404 } |
405 | 405 |
406 SetVisible(true); | 406 SetVisible(true); |
407 if (resize_area_) | 407 if (resize_area_) |
408 resize_area_->SetBounds(0, 0, platform_settings().item_spacing, height()); | 408 resize_area_->SetBounds(0, 0, platform_settings().item_spacing, height()); |
409 | 409 |
410 // The range of visible icons, from start_index (inclusive) to end_index | |
411 // (exclusive). | |
412 size_t start_index = toolbar_actions_bar_->GetStartIndexInBounds(); | |
413 size_t end_index = toolbar_actions_bar_->GetEndIndexInBounds(); | |
414 | |
410 // If the icons don't all fit, show the chevron (unless suppressed). | 415 // If the icons don't all fit, show the chevron (unless suppressed). |
411 int max_x = GetPreferredSize().width(); | 416 if (end_index != toolbar_action_views_.size() && !suppress_chevron_ && |
412 if (toolbar_actions_bar_->IconCountToWidth(-1) > max_x && | 417 chevron_) { |
413 !suppress_chevron_ && chevron_) { | |
414 chevron_->SetVisible(true); | 418 chevron_->SetVisible(true); |
415 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 419 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
416 max_x -= chevron_size.width() + kChevronSpacing; | |
417 chevron_->SetBounds( | 420 chevron_->SetBounds( |
418 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 421 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
419 0, | 422 0, |
420 chevron_size.width(), | 423 chevron_size.width(), |
421 chevron_size.height()); | 424 chevron_size.height()); |
422 } else if (chevron_) { | 425 } else if (chevron_) { |
423 chevron_->SetVisible(false); | 426 chevron_->SetVisible(false); |
424 } | 427 } |
425 | 428 |
426 // The range of visible icons, from start_index (inclusive) to end_index | |
427 // (exclusive). | |
428 size_t start_index = in_overflow_mode() ? | |
429 toolbar_action_views_.size() - toolbar_actions_bar_->GetIconCount() : 0u; | |
430 // For the main container's last visible icon, we calculate how many icons we | |
431 // can display with the given width. We add an extra item_spacing because the | |
432 // last icon doesn't need padding, but we want it to divide easily. | |
433 size_t end_index = in_overflow_mode() ? | |
434 toolbar_action_views_.size() : | |
435 (max_x - platform_settings().left_padding - | |
436 platform_settings().right_padding + | |
437 platform_settings().item_spacing) / | |
438 ToolbarActionsBar::IconWidth(true); | |
439 | |
440 // Now draw the icons for the actions in the available space. Once all the | 429 // Now draw the icons for the actions in the available space. Once all the |
441 // variables are in place, the layout works equally well for the main and | 430 // variables are in place, the layout works equally well for the main and |
442 // overflow container. | 431 // overflow container. |
443 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { | 432 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { |
444 ToolbarActionView* view = toolbar_action_views_[i]; | 433 ToolbarActionView* view = toolbar_action_views_[i]; |
445 if (i < start_index || i >= end_index) { | 434 if (i < start_index || i >= end_index) { |
446 view->SetVisible(false); | 435 view->SetVisible(false); |
447 } else { | 436 } else { |
448 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i)); | 437 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i)); |
449 view->SetVisible(true); | 438 view->SetVisible(true); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 const gfx::Point& press_pt, | 612 const gfx::Point& press_pt, |
624 const gfx::Point& p) { | 613 const gfx::Point& p) { |
625 // We don't allow dragging while we're highlighting. | 614 // We don't allow dragging while we're highlighting. |
626 return !toolbar_actions_bar_->is_highlighting(); | 615 return !toolbar_actions_bar_->is_highlighting(); |
627 } | 616 } |
628 | 617 |
629 void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) { | 618 void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) { |
630 // We don't allow resize while the toolbar is highlighting a subset of | 619 // We don't allow resize while the toolbar is highlighting a subset of |
631 // actions, since this is a temporary and entirely browser-driven sequence in | 620 // actions, since this is a temporary and entirely browser-driven sequence in |
632 // order to warn the user about potentially dangerous items. | 621 // order to warn the user about potentially dangerous items. |
633 if (toolbar_actions_bar_->is_highlighting()) | 622 // We also don't allow resize when the bar is already animating, since we |
623 // don't want two competing size changes. | |
624 if (toolbar_actions_bar_->is_highlighting() || animating()) | |
634 return; | 625 return; |
635 | 626 |
636 if (!done_resizing) { | 627 if (!done_resizing) { |
628 // If this is the start of the resize gesture, then set |container_width_| | |
629 // to be the current width. It might not have been if the container was | |
630 // shrank to give room to the omnibox, but to adjust the size, it needs to | |
Peter Kasting
2015/09/15 00:13:38
Nit: shrunk (or remove "was" on previous line)
Devlin
2015/09/15 18:22:39
Done.
| |
631 // be accurate. | |
632 if (!resize_amount_) | |
633 container_width_ = width(); | |
634 | |
637 resize_amount_ = resize_amount; | 635 resize_amount_ = resize_amount; |
638 Redraw(false); | 636 Redraw(false); |
639 return; | 637 return; |
640 } | 638 } |
641 | 639 |
642 // Up until now we've only been modifying the resize_amount, but now it is | 640 // Up until now we've only been modifying the resize_amount, but now it is |
643 // time to set the container size to the size we have resized to, and then | 641 // time to set the container size to the size we have resized to, and then |
644 // animate to the nearest icon count size if necessary (which may be 0). | 642 // animate to the nearest icon count size if necessary (which may be 0). |
645 container_width_ = | 643 container_width_ = |
646 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(), | 644 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 warning_highlight_painter_.reset( | 785 warning_highlight_painter_.reset( |
788 views::Painter::CreateImageGridPainter(kWarningImages)); | 786 views::Painter::CreateImageGridPainter(kWarningImages)); |
789 } | 787 } |
790 | 788 |
791 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { | 789 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { |
792 DCHECK(active_bubble_); | 790 DCHECK(active_bubble_); |
793 DCHECK_EQ(active_bubble_->GetWidget(), widget); | 791 DCHECK_EQ(active_bubble_->GetWidget(), widget); |
794 widget->RemoveObserver(this); | 792 widget->RemoveObserver(this); |
795 active_bubble_ = nullptr; | 793 active_bubble_ = nullptr; |
796 } | 794 } |
OLD | NEW |