Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 1330423003: [Extensions Toolbar] Protect against crazy bounds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final nits Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 (chevron_ && !suppress_chevron_ && toolbar_actions_bar_->NeedsOverflow()) {
412 if (toolbar_actions_bar_->IconCountToWidth(-1) > max_x &&
413 !suppress_chevron_ && chevron_) {
414 chevron_->SetVisible(true); 417 chevron_->SetVisible(true);
415 gfx::Size chevron_size(chevron_->GetPreferredSize()); 418 gfx::Size chevron_size(chevron_->GetPreferredSize());
416 max_x -= chevron_size.width() + kChevronSpacing;
417 chevron_->SetBounds( 419 chevron_->SetBounds(
418 width() - ToolbarView::kStandardSpacing - chevron_size.width(), 420 width() - ToolbarView::kStandardSpacing - chevron_size.width(),
419 0, 421 0,
420 chevron_size.width(), 422 chevron_size.width(),
421 chevron_size.height()); 423 chevron_size.height());
422 } else if (chevron_) { 424 } else if (chevron_) {
423 chevron_->SetVisible(false); 425 chevron_->SetVisible(false);
424 } 426 }
425 427
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 428 // 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 429 // variables are in place, the layout works equally well for the main and
442 // overflow container. 430 // overflow container.
443 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { 431 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) {
444 ToolbarActionView* view = toolbar_action_views_[i]; 432 ToolbarActionView* view = toolbar_action_views_[i];
445 if (i < start_index || i >= end_index) { 433 if (i < start_index || i >= end_index) {
446 view->SetVisible(false); 434 view->SetVisible(false);
447 } else { 435 } else {
448 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i)); 436 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i));
449 view->SetVisible(true); 437 view->SetVisible(true);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 const gfx::Point& press_pt, 611 const gfx::Point& press_pt,
624 const gfx::Point& p) { 612 const gfx::Point& p) {
625 // We don't allow dragging while we're highlighting. 613 // We don't allow dragging while we're highlighting.
626 return !toolbar_actions_bar_->is_highlighting(); 614 return !toolbar_actions_bar_->is_highlighting();
627 } 615 }
628 616
629 void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) { 617 void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) {
630 // We don't allow resize while the toolbar is highlighting a subset of 618 // 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 619 // actions, since this is a temporary and entirely browser-driven sequence in
632 // order to warn the user about potentially dangerous items. 620 // order to warn the user about potentially dangerous items.
633 if (toolbar_actions_bar_->is_highlighting()) 621 // We also don't allow resize when the bar is already animating, since we
622 // don't want two competing size changes.
623 if (toolbar_actions_bar_->is_highlighting() || animating())
634 return; 624 return;
635 625
636 if (!done_resizing) { 626 if (!done_resizing) {
627 // If this is the start of the resize gesture, then set |container_width_|
628 // to be the current width. It might not have been if the container was
629 // shrunk to give room to the omnibox, but to adjust the size, it needs to
630 // be accurate.
631 if (!resize_amount_)
632 container_width_ = width();
633
637 resize_amount_ = resize_amount; 634 resize_amount_ = resize_amount;
638 Redraw(false); 635 Redraw(false);
639 return; 636 return;
640 } 637 }
641 638
642 // Up until now we've only been modifying the resize_amount, but now it is 639 // 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 640 // 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). 641 // animate to the nearest icon count size if necessary (which may be 0).
645 container_width_ = 642 container_width_ =
646 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(), 643 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 warning_highlight_painter_.reset( 784 warning_highlight_painter_.reset(
788 views::Painter::CreateImageGridPainter(kWarningImages)); 785 views::Painter::CreateImageGridPainter(kWarningImages));
789 } 786 }
790 787
791 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { 788 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) {
792 DCHECK(active_bubble_); 789 DCHECK(active_bubble_);
793 DCHECK_EQ(active_bubble_->GetWidget(), widget); 790 DCHECK_EQ(active_bubble_->GetWidget(), widget);
794 widget->RemoveObserver(this); 791 widget->RemoveObserver(this);
795 active_bubble_ = nullptr; 792 active_bubble_ = nullptr;
796 } 793 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698