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

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

Issue 3052011: Make the resize gripper invisible.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/browser_actions_container.h" 5 #include "chrome/browser/views/browser_actions_container.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/slide_animation.h" 9 #include "app/slide_animation.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // The padding above and below the divider. 69 // The padding above and below the divider.
70 static const int kDividerVerticalPadding = 9; 70 static const int kDividerVerticalPadding = 9;
71 71
72 // The margin above the chevron. 72 // The margin above the chevron.
73 static const int kChevronTopMargin = 9; 73 static const int kChevronTopMargin = 9;
74 74
75 // The margin to the right of the chevron. 75 // The margin to the right of the chevron.
76 static const int kChevronRightMargin = 4; 76 static const int kChevronRightMargin = 4;
77 77
78 // Extra hit-area for the resize gripper. 78 // Width for the resize area.
79 static const int kExtraResizeArea = 4; 79 static const int kResizeAreaWidth = 4;
80 80
81 // Width of the drop indicator. 81 // Width of the drop indicator.
82 static const int kDropIndicatorWidth = 2; 82 static const int kDropIndicatorWidth = 2;
83 83
84 // Color of the drop indicator. 84 // Color of the drop indicator.
85 static const SkColor kDropIndicatorColor = SK_ColorBLACK; 85 static const SkColor kDropIndicatorColor = SK_ColorBLACK;
86 86
87 // The x offset for the drop indicator (how much we shift it by). 87 // The x offset for the drop indicator (how much we shift it by).
88 static const int kDropIndicatorOffsetLtr = 3; 88 static const int kDropIndicatorOffsetLtr = 3;
89 static const int kDropIndicatorOffsetRtl = 9; 89 static const int kDropIndicatorOffsetRtl = 9;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // BrowserActionsContainer 360 // BrowserActionsContainer
361 361
362 BrowserActionsContainer::BrowserActionsContainer( 362 BrowserActionsContainer::BrowserActionsContainer(
363 Browser* browser, View* owner_view) 363 Browser* browser, View* owner_view)
364 : profile_(browser->profile()), 364 : profile_(browser->profile()),
365 browser_(browser), 365 browser_(browser),
366 owner_view_(owner_view), 366 owner_view_(owner_view),
367 popup_(NULL), 367 popup_(NULL),
368 popup_button_(NULL), 368 popup_button_(NULL),
369 model_(NULL), 369 model_(NULL),
370 resize_gripper_(NULL),
371 chevron_(NULL), 370 chevron_(NULL),
372 overflow_menu_(NULL), 371 overflow_menu_(NULL),
373 suppress_chevron_(false), 372 suppress_chevron_(false),
374 resize_amount_(0), 373 resize_amount_(0),
375 animation_target_size_(0), 374 animation_target_size_(0),
376 drop_indicator_position_(-1), 375 drop_indicator_position_(-1),
377 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), 376 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
378 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { 377 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) {
379 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); 378 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR);
380 379
381 if (profile_->GetExtensionsService()) { 380 if (profile_->GetExtensionsService()) {
382 model_ = profile_->GetExtensionsService()->toolbar_model(); 381 model_ = profile_->GetExtensionsService()->toolbar_model();
383 model_->AddObserver(this); 382 model_->AddObserver(this);
384 } 383 }
385 resize_animation_.reset(new SlideAnimation(this)); 384 resize_animation_.reset(new SlideAnimation(this));
386 resize_gripper_ = new views::ResizeGripper(this); 385 resize_area_ = new views::ResizeArea(this);
387 resize_gripper_->SetAccessibleName( 386 resize_area_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_SEPARATOR));
388 l10n_util::GetString(IDS_ACCNAME_SEPARATOR)); 387 AddChildView(resize_area_);
389 resize_gripper_->SetVisible(false);
390 AddChildView(resize_gripper_);
391 388
392 // TODO(glen): Come up with a new bitmap for the chevron. 389 // TODO(glen): Come up with a new bitmap for the chevron.
393 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 390 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
394 SkBitmap* chevron_image = rb.GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS); 391 SkBitmap* chevron_image = rb.GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS);
395 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); 392 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false);
396 chevron_->SetVisible(false); 393 chevron_->SetVisible(false);
397 chevron_->SetIcon(*chevron_image); 394 chevron_->SetIcon(*chevron_image);
398 chevron_->SetAccessibleName( 395 chevron_->SetAccessibleName(
399 l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_CHEVRON)); 396 l10n_util::GetString(IDS_ACCNAME_EXTENSIONS_CHEVRON));
400 // Chevron contains >> that should point left in LTR locales. 397 // Chevron contains >> that should point left in LTR locales.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 for (size_t i = 0; i < browser_action_views_.size(); ++i) 510 for (size_t i = 0; i < browser_action_views_.size(); ++i)
514 RemoveChildView(browser_action_views_[i]); 511 RemoveChildView(browser_action_views_[i]);
515 STLDeleteContainerPointers(browser_action_views_.begin(), 512 STLDeleteContainerPointers(browser_action_views_.begin(),
516 browser_action_views_.end()); 513 browser_action_views_.end());
517 browser_action_views_.clear(); 514 browser_action_views_.clear();
518 } 515 }
519 } 516 }
520 517
521 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 518 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
522 SetVisible(browser_action_views_.size() > 0); 519 SetVisible(browser_action_views_.size() > 0);
523 resize_gripper_->SetVisible(browser_action_views_.size() > 0);
524
525 owner_view_->Layout(); 520 owner_view_->Layout();
526 owner_view_->SchedulePaint(); 521 owner_view_->SchedulePaint();
527 } 522 }
528 523
529 void BrowserActionsContainer::HidePopup() { 524 void BrowserActionsContainer::HidePopup() {
530 if (popup_) 525 if (popup_)
531 popup_->Close(); 526 popup_->Close();
532 } 527 }
533 528
534 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { 529 void BrowserActionsContainer::TestExecuteBrowserAction(int index) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 container_size_.width() - resize_amount_); 601 container_size_.width() - resize_amount_);
607 int max_width = ClampToNearestIconCount(-1, false); // -1 gives max width. 602 int max_width = ClampToNearestIconCount(-1, false); // -1 gives max width.
608 width = std::min(width, max_width); 603 width = std::min(width, max_width);
609 604
610 return gfx::Size(width, kButtonSize); 605 return gfx::Size(width, kButtonSize);
611 } 606 }
612 607
613 void BrowserActionsContainer::Layout() { 608 void BrowserActionsContainer::Layout() {
614 if (browser_action_views_.size() == 0) { 609 if (browser_action_views_.size() == 0) {
615 SetVisible(false); 610 SetVisible(false);
616 resize_gripper_->SetVisible(false);
617 chevron_->SetVisible(false); 611 chevron_->SetVisible(false);
618 return; 612 return;
619 } else { 613 } else {
620 SetVisible(true); 614 SetVisible(true);
621 resize_gripper_->SetVisible(true);
622 } 615 }
623 616
624 int x = 0; 617 resize_area_->SetBounds(0, 0, kResizeAreaWidth, height());
625 if (resize_gripper_->IsVisible()) { 618 int x = kResizeAreaWidth;
626 // We'll draw the resize gripper a little wider, to add some invisible hit
627 // target area - but we don't account for it anywhere.
628 gfx::Size sz = resize_gripper_->GetPreferredSize();
629 resize_gripper_->SetBounds(x, (height() - sz.height()) / 2 + 1,
630 sz.width() + kExtraResizeArea, sz.height());
631 x += sz.width();
632 }
633 619
634 x += base::i18n::IsRTL() ? kHorizontalPaddingRtl : kHorizontalPadding; 620 x += base::i18n::IsRTL() ? kHorizontalPaddingRtl : kHorizontalPadding;
635 621
636 // Calculate if all icons fit without showing the chevron. We need to know 622 // Calculate if all icons fit without showing the chevron. We need to know
637 // this beforehand, because showing the chevron will decrease the space that 623 // this beforehand, because showing the chevron will decrease the space that
638 // we have to draw the visible ones (ie. if one icon is visible and another 624 // we have to draw the visible ones (ie. if one icon is visible and another
639 // doesn't have enough room). 625 // doesn't have enough room).
640 int last_x_of_icons = x + 626 int last_x_of_icons = x +
641 (browser_action_views_.size() * kButtonSize) + 627 (browser_action_views_.size() * kButtonSize) +
642 ((browser_action_views_.size() - 1) * 628 ((browser_action_views_.size() - 1) *
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 int pixelWidth, bool allow_shrink_to_minimum) const { 877 int pixelWidth, bool allow_shrink_to_minimum) const {
892 // Calculate the width of one icon. 878 // Calculate the width of one icon.
893 int icon_width = (kButtonSize + kBrowserActionButtonPadding); 879 int icon_width = (kButtonSize + kBrowserActionButtonPadding);
894 880
895 // Calculate pixel count for the area not used by the icons. 881 // Calculate pixel count for the area not used by the icons.
896 int extras = WidthOfNonIconArea(); 882 int extras = WidthOfNonIconArea();
897 883
898 size_t icon_count = 0u; 884 size_t icon_count = 0u;
899 if (pixelWidth >= 0) { 885 if (pixelWidth >= 0) {
900 // Caller wants to know how many icons fit within a given space so we start 886 // Caller wants to know how many icons fit within a given space so we start
901 // by subtracting the padding, gripper and dividers. 887 // by subtracting the padding, resize area and dividers.
902 int icon_area = pixelWidth - extras; 888 int icon_area = pixelWidth - extras;
903 icon_area = std::max(0, icon_area); 889 icon_area = std::max(0, icon_area);
904 890
905 // Make sure we never throw an icon into the chevron menu just because 891 // Make sure we never throw an icon into the chevron menu just because
906 // there isn't enough enough space for the invisible padding around buttons. 892 // there isn't enough enough space for the invisible padding around buttons.
907 icon_area += kBrowserActionButtonPadding - 1; 893 icon_area += kBrowserActionButtonPadding - 1;
908 894
909 // Count the number of icons that fit within that area. 895 // Count the number of icons that fit within that area.
910 icon_count = icon_area / icon_width; 896 icon_count = icon_area / icon_width;
911 897
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 else 1026 else
1041 chevron_->SetVisible(true); 1027 chevron_->SetVisible(true);
1042 container_size_ = gfx::Size(IconCountToWidth(visible_actions), kButtonSize); 1028 container_size_ = gfx::Size(IconCountToWidth(visible_actions), kButtonSize);
1043 } 1029 }
1044 1030
1045 int BrowserActionsContainer::WidthOfNonIconArea() const { 1031 int BrowserActionsContainer::WidthOfNonIconArea() const {
1046 int chevron_size = (chevron_->IsVisible()) ? 1032 int chevron_size = (chevron_->IsVisible()) ?
1047 chevron_->GetPreferredSize().width() : 0; 1033 chevron_->GetPreferredSize().width() : 0;
1048 int padding = base::i18n::IsRTL() ? 1034 int padding = base::i18n::IsRTL() ?
1049 kHorizontalPaddingRtl : kHorizontalPadding; 1035 kHorizontalPaddingRtl : kHorizontalPadding;
1050 return resize_gripper_->GetPreferredSize().width() + padding + 1036 return kResizeAreaWidth + padding + chevron_size + kChevronRightMargin +
1051 chevron_size + kChevronRightMargin + kDividerHorizontalMargin; 1037 kDividerHorizontalMargin;
1052 } 1038 }
1053 1039
1054 int BrowserActionsContainer::IconCountToWidth(int icons) const { 1040 int BrowserActionsContainer::IconCountToWidth(int icons) const {
1055 DCHECK_GE(icons, 0); 1041 DCHECK_GE(icons, 0);
1056 if (icons == 0) 1042 if (icons == 0)
1057 return ContainerMinSize(); 1043 return ContainerMinSize();
1058 1044
1059 int icon_width = kButtonSize + kBrowserActionButtonPadding; 1045 int icon_width = kButtonSize + kBrowserActionButtonPadding;
1060 1046
1061 return WidthOfNonIconArea() + (icons * icon_width); 1047 return WidthOfNonIconArea() + (icons * icon_width);
1062 } 1048 }
1063 1049
1064 int BrowserActionsContainer::ContainerMinSize() const { 1050 int BrowserActionsContainer::ContainerMinSize() const {
1065 return resize_gripper_->width() + chevron_->width() + kChevronRightMargin; 1051 return kResizeAreaWidth + chevron_->width() + kChevronRightMargin;
1066 } 1052 }
1067 1053
1068 void BrowserActionsContainer::Animate(Tween::Type tween_type, int target_size) { 1054 void BrowserActionsContainer::Animate(Tween::Type tween_type, int target_size) {
1069 if (!disable_animations_during_testing_) { 1055 if (!disable_animations_during_testing_) {
1070 // Animate! We have to set the animation_target_size_ after calling Reset(), 1056 // Animate! We have to set the animation_target_size_ after calling Reset(),
1071 // because that could end up calling AnimationEnded which clears the value. 1057 // because that could end up calling AnimationEnded which clears the value.
1072 resize_animation_->Reset(); 1058 resize_animation_->Reset();
1073 resize_animation_->SetTweenType(tween_type); 1059 resize_animation_->SetTweenType(tween_type);
1074 animation_target_size_ = target_size; 1060 animation_target_size_ = target_size;
1075 resize_animation_->Show(); 1061 resize_animation_->Show();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 popup_ = NULL; 1143 popup_ = NULL;
1158 popup_button_->SetButtonNotPushed(); 1144 popup_button_->SetButtonNotPushed();
1159 popup_button_ = NULL; 1145 popup_button_ = NULL;
1160 } 1146 }
1161 1147
1162 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { 1148 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) {
1163 // Only display incognito-enabled extensions while in incognito mode. 1149 // Only display incognito-enabled extensions while in incognito mode.
1164 return (!profile_->IsOffTheRecord() || 1150 return (!profile_->IsOffTheRecord() ||
1165 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); 1151 profile_->GetExtensionsService()->IsIncognitoEnabled(extension));
1166 } 1152 }
OLDNEW
« no previous file with comments | « chrome/browser/views/browser_actions_container.h ('k') | chrome/browser/views/extensions/extension_installed_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698