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

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

Issue 1469423002: Modify toolbar action bar layout for material design (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more comments addressed Created 5 years 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"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d elegate.h" 13 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d elegate.h"
14 #include "chrome/browser/ui/layout_constants.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 16 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 17 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
17 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" 18 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
18 #include "chrome/browser/ui/view_ids.h" 19 #include "chrome/browser/ui/view_ids.h"
19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
20 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" 21 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h"
21 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu bble_views.h" 22 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu bble_views.h"
22 #include "chrome/browser/ui/views/frame/browser_view.h" 23 #include "chrome/browser/ui/views/frame/browser_view.h"
23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 24 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
25 #include "chrome/common/extensions/command.h" 26 #include "chrome/common/extensions/command.h"
26 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
27 #include "extensions/common/feature_switch.h" 28 #include "extensions/common/feature_switch.h"
28 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
29 #include "third_party/skia/include/core/SkColor.h" 30 #include "third_party/skia/include/core/SkColor.h"
30 #include "ui/accessibility/ax_view_state.h" 31 #include "ui/accessibility/ax_view_state.h"
31 #include "ui/base/dragdrop/drag_utils.h" 32 #include "ui/base/dragdrop/drag_utils.h"
32 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/nine_image_painter_factory.h" 34 #include "ui/base/nine_image_painter_factory.h"
35 #include "ui/base/resource/material_design/material_design_controller.h"
34 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/base/theme_provider.h" 37 #include "ui/base/theme_provider.h"
36 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/geometry/rect.h" 39 #include "ui/gfx/geometry/rect.h"
38 #include "ui/resources/grit/ui_resources.h" 40 #include "ui/resources/grit/ui_resources.h"
39 #include "ui/views/bubble/bubble_delegate.h" 41 #include "ui/views/bubble/bubble_delegate.h"
40 #include "ui/views/controls/resize_area.h" 42 #include "ui/views/controls/resize_area.h"
41 #include "ui/views/painter.h" 43 #include "ui/views/painter.h"
42 #include "ui/views/widget/widget.h" 44 #include "ui/views/widget/widget.h"
43 45
44 namespace { 46 namespace {
45 47
46 // Horizontal spacing before the chevron (if visible). 48 // Horizontal spacing before the chevron (if visible).
47 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; 49 // TODO(tdanderson): In material design, the chevron should have the same size
50 // and vertical spacing as the other action buttons.
51 int GetChevronSpacing() {
52 return GetLayoutConstant(TOOLBAR_STANDARD_SPACING) - 2;
53 }
48 54
49 // Returns the ToolbarView for the given |browser|. 55 // Returns the ToolbarView for the given |browser|.
50 ToolbarView* GetToolbarView(Browser* browser) { 56 ToolbarView* GetToolbarView(Browser* browser) {
51 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); 57 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar();
52 } 58 }
53 59
54 } // namespace 60 } // namespace
55 61
56 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
57 // BrowserActionsContainer::DropPosition 63 // BrowserActionsContainer::DropPosition
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 bool BrowserActionsContainer::IsAnimating() const { 314 bool BrowserActionsContainer::IsAnimating() const {
309 return animating(); 315 return animating();
310 } 316 }
311 317
312 void BrowserActionsContainer::StopAnimating() { 318 void BrowserActionsContainer::StopAnimating() {
313 animation_target_size_ = width(); 319 animation_target_size_ = width();
314 resize_animation_->Reset(); 320 resize_animation_->Reset();
315 } 321 }
316 322
317 int BrowserActionsContainer::GetChevronWidth() const { 323 int BrowserActionsContainer::GetChevronWidth() const {
318 return chevron_ ? chevron_->GetPreferredSize().width() + kChevronSpacing : 0; 324 return chevron_ ?
325 chevron_->GetPreferredSize().width() + GetChevronSpacing() : 0;
319 } 326 }
320 327
321 void BrowserActionsContainer::ShowExtensionMessageBubble( 328 void BrowserActionsContainer::ShowExtensionMessageBubble(
322 scoped_ptr<extensions::ExtensionMessageBubbleController> controller, 329 scoped_ptr<extensions::ExtensionMessageBubbleController> controller,
323 ToolbarActionViewController* anchor_action) { 330 ToolbarActionViewController* anchor_action) {
324 // The container shouldn't be asked to show a bubble if it's animating. 331 // The container shouldn't be asked to show a bubble if it's animating.
325 DCHECK(!animating()); 332 DCHECK(!animating());
326 333
327 views::View* reference_view = 334 views::View* reference_view =
328 anchor_action 335 anchor_action
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // The range of visible icons, from start_index (inclusive) to end_index 417 // The range of visible icons, from start_index (inclusive) to end_index
411 // (exclusive). 418 // (exclusive).
412 size_t start_index = toolbar_actions_bar_->GetStartIndexInBounds(); 419 size_t start_index = toolbar_actions_bar_->GetStartIndexInBounds();
413 size_t end_index = toolbar_actions_bar_->GetEndIndexInBounds(); 420 size_t end_index = toolbar_actions_bar_->GetEndIndexInBounds();
414 421
415 // If the icons don't all fit, show the chevron (unless suppressed). 422 // If the icons don't all fit, show the chevron (unless suppressed).
416 if (chevron_ && !suppress_chevron_ && toolbar_actions_bar_->NeedsOverflow()) { 423 if (chevron_ && !suppress_chevron_ && toolbar_actions_bar_->NeedsOverflow()) {
417 chevron_->SetVisible(true); 424 chevron_->SetVisible(true);
418 gfx::Size chevron_size(chevron_->GetPreferredSize()); 425 gfx::Size chevron_size(chevron_->GetPreferredSize());
419 chevron_->SetBounds( 426 chevron_->SetBounds(
420 width() - ToolbarView::kStandardSpacing - chevron_size.width(), 427 width() - GetLayoutConstant(TOOLBAR_STANDARD_SPACING) -
428 chevron_size.width(),
421 0, 429 0,
422 chevron_size.width(), 430 chevron_size.width(),
423 chevron_size.height()); 431 chevron_size.height());
424 } else if (chevron_) { 432 } else if (chevron_) {
425 chevron_->SetVisible(false); 433 chevron_->SetVisible(false);
426 } 434 }
427 435
428 // Now draw the icons for the actions in the available space. Once all the 436 // Now draw the icons for the actions in the available space. Once all the
429 // variables are in place, the layout works equally well for the main and 437 // variables are in place, the layout works equally well for the main and
430 // overflow container. 438 // overflow container.
(...skipping 28 matching lines...) Expand all
459 467
460 int BrowserActionsContainer::OnDragUpdated( 468 int BrowserActionsContainer::OnDragUpdated(
461 const ui::DropTargetEvent& event) { 469 const ui::DropTargetEvent& event) {
462 size_t row_index = 0; 470 size_t row_index = 0;
463 size_t before_icon_in_row = 0; 471 size_t before_icon_in_row = 0;
464 // If there are no visible actions (such as when dragging an icon to an empty 472 // If there are no visible actions (such as when dragging an icon to an empty
465 // overflow/main container), then 0, 0 for row, column is correct. 473 // overflow/main container), then 0, 0 for row, column is correct.
466 if (VisibleBrowserActions() != 0) { 474 if (VisibleBrowserActions() != 0) {
467 // Figure out where to display the indicator. This is a complex calculation: 475 // Figure out where to display the indicator. This is a complex calculation:
468 476
469 // First, we subtract out the padding to the left of the icon area, which is 477 // First, we subtract out the padding to the left of the icon area. If
470 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the 478 // we're right-to-left, we also mirror the event.x() so that our
471 // event.x() so that our calculations are consistent with left-to-right. 479 // calculations are consistent with left-to-right.
472 int offset_into_icon_area = 480 int offset_into_icon_area =
473 GetMirroredXInView(event.x()) - ToolbarView::kStandardSpacing; 481 GetMirroredXInView(event.x()) -
482 GetLayoutConstant(TOOLBAR_STANDARD_SPACING);
474 483
475 // Next, figure out what row we're on. This only matters for overflow mode, 484 // Next, figure out what row we're on. This only matters for overflow mode,
476 // but the calculation is the same for both. 485 // but the calculation is the same for both.
477 row_index = event.y() / ToolbarActionsBar::IconHeight(); 486 row_index = event.y() / ToolbarActionsBar::IconHeight();
478 487
479 // Sanity check - we should never be on a different row in the main 488 // Sanity check - we should never be on a different row in the main
480 // container. 489 // container.
481 DCHECK(in_overflow_mode() || row_index == 0); 490 DCHECK(in_overflow_mode() || row_index == 0);
482 491
483 // Next, we determine which icon to place the indicator in front of. We want 492 // Next, we determine which icon to place the indicator in front of. We want
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 706 }
698 707
699 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while 708 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while
700 // dragging (like we do for tab dragging). 709 // dragging (like we do for tab dragging).
701 if (drop_position_.get()) { 710 if (drop_position_.get()) {
702 // The two-pixel width drop indicator. 711 // The two-pixel width drop indicator.
703 static const int kDropIndicatorWidth = 2; 712 static const int kDropIndicatorWidth = 2;
704 713
705 // Convert back to a pixel offset into the container. First find the X 714 // Convert back to a pixel offset into the container. First find the X
706 // coordinate of the drop icon. 715 // coordinate of the drop icon.
707 int drop_icon_x = ToolbarView::kStandardSpacing + 716 const int drop_icon_x = GetLayoutConstant(TOOLBAR_STANDARD_SPACING) +
708 (drop_position_->icon_in_row * ToolbarActionsBar::IconWidth(true)); 717 (drop_position_->icon_in_row * ToolbarActionsBar::IconWidth(true));
709 // Next, find the space before the drop icon. This will either be 718 // Next, find the space before the drop icon.
710 // left padding or item spacing, depending on whether this is the first 719 const int space_before_drop_icon = platform_settings().item_spacing;
711 // icon.
712 // NOTE: Right now, these are the same. But let's do this right for if they
713 // ever aren't.
714 int space_before_drop_icon = drop_position_->icon_in_row == 0 ?
715 platform_settings().left_padding : platform_settings().item_spacing;
716 // Now place the drop indicator halfway between this and the end of the 720 // Now place the drop indicator halfway between this and the end of the
717 // previous icon. If there is an odd amount of available space between the 721 // previous icon. If there is an odd amount of available space between the
718 // two icons (or the icon and the address bar) after subtracting the drop 722 // two icons (or the icon and the address bar) after subtracting the drop
719 // indicator width, this calculation puts the extra pixel on the left side 723 // indicator width, this calculation puts the extra pixel on the left side
720 // of the indicator, since when the indicator is between the address bar and 724 // of the indicator, since when the indicator is between the address bar and
721 // the first icon, it looks better closer to the icon. 725 // the first icon, it looks better closer to the icon.
722 int drop_indicator_x = drop_icon_x - 726 const int drop_indicator_x = drop_icon_x -
723 ((space_before_drop_icon + kDropIndicatorWidth) / 2); 727 ((space_before_drop_icon + kDropIndicatorWidth) / 2);
724 int row_height = ToolbarActionsBar::IconHeight(); 728 const int row_height = ToolbarActionsBar::IconHeight();
725 int drop_indicator_y = row_height * drop_position_->row; 729 const int drop_indicator_y = row_height * drop_position_->row;
726 gfx::Rect indicator_bounds(drop_indicator_x, 730 gfx::Rect indicator_bounds(drop_indicator_x,
727 drop_indicator_y, 731 drop_indicator_y,
728 kDropIndicatorWidth, 732 kDropIndicatorWidth,
729 row_height); 733 row_height);
730 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds)); 734 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds));
731 735
732 // Color of the drop indicator. 736 // Color of the drop indicator.
733 static const SkColor kDropIndicatorColor = SK_ColorBLACK; 737 static const SkColor kDropIndicatorColor = SK_ColorBLACK;
734 canvas->FillRect(indicator_bounds, kDropIndicatorColor); 738 canvas->FillRect(indicator_bounds, kDropIndicatorColor);
735 } 739 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 warning_highlight_painter_.reset( 785 warning_highlight_painter_.reset(
782 views::Painter::CreateImageGridPainter(kWarningImages)); 786 views::Painter::CreateImageGridPainter(kWarningImages));
783 } 787 }
784 788
785 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { 789 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) {
786 DCHECK(active_bubble_); 790 DCHECK(active_bubble_);
787 DCHECK_EQ(active_bubble_->GetWidget(), widget); 791 DCHECK_EQ(active_bubble_->GetWidget(), widget);
788 widget->RemoveObserver(this); 792 widget->RemoveObserver(this);
789 active_bubble_ = nullptr; 793 active_bubble_ = nullptr;
790 } 794 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.h ('k') | chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698