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

Side by Side Diff: ash/shelf/shelf_tooltip_manager.cc

Issue 2174643002: [ash-md] Updates ash shelf tooltips to MD (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [ash-md] Updates ash shelf tooltips to MD (no new shadow type) Created 4 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
« no previous file with comments | « no previous file | ui/views/bubble/bubble_border.h » ('j') | ui/views/bubble/bubble_border.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/shelf/shelf_tooltip_manager.h" 5 #include "ash/shelf/shelf_tooltip_manager.h"
6 6
7 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/shelf/shelf.h" 8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_view.h" 10 #include "ash/shelf/shelf_view.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/window_animations.h" 12 #include "ash/wm/window_animations.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/events/event_constants.h" 19 #include "ui/events/event_constants.h"
20 #include "ui/gfx/geometry/insets.h" 20 #include "ui/gfx/geometry/insets.h"
21 #include "ui/views/bubble/bubble_dialog_delegate.h" 21 #include "ui/views/bubble/bubble_dialog_delegate.h"
22 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
23 #include "ui/views/layout/fill_layout.h" 23 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 #include "ui/wm/core/window_animations.h" 25 #include "ui/wm/core/window_animations.h"
26 26
27 namespace ash { 27 namespace ash {
28 namespace { 28 namespace {
29 29
30 const int kTooltipTopBottomMargin = 3;
31 const int kTooltipLeftRightMargin = 10;
32 const int kTooltipAppearanceDelay = 1000; // msec 30 const int kTooltipAppearanceDelay = 1000; // msec
33 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; 31
34 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); 32 // Tooltip layout constants.
33
34 // Shelf item tooltip height.
35 const int kTooltipHeight = 24;
35 36
36 // The maximum width of the tooltip bubble. Borrowed the value from 37 // The maximum width of the tooltip bubble. Borrowed the value from
37 // ash/tooltip/tooltip_controller.cc 38 // ash/tooltip/tooltip_controller.cc
38 const int kTooltipMaxWidth = 250; 39 const int kTooltipMaxWidth = 250;
39 40
40 // The offset for the tooltip bubble - making sure that the bubble is flush 41 // Shelf item tooltip internal text margins.
41 // with the shelf. The offset includes the arrow size in pixels as well as 42 const int kTooltipTopBottomMargin = 4;
42 // the activation bar and other spacing elements. 43 const int kTooltipLeftRightMargin = 8;
43 const int kArrowOffsetLeftRight = 11; 44
44 const int kArrowOffsetTopBottom = 7; 45 // The offset for the tooltip bubble - making sure that the bubble is spaced
46 // with a fixed gap. The gap is accounted for by the transparent arrow in the
47 // bubble and an additional 1px padding for the shelf item views.
James Cook 2016/07/25 17:01:08 I like that you write detailed documentation for l
varkha 2016/07/26 19:19:59 Acknowledged.
48 const int kArrowTopBottomOffset = 1;
49 const int kArrowLeftRightOffset = 1;
50
51 // Tooltip's border interior thickness that defines its minimum height.
52 const int kBorderInteriorThickness = kTooltipHeight / 2;
45 53
46 } // namespace 54 } // namespace
47 55
48 // The implementation of tooltip of the launcher. 56 // The implementation of tooltip of the launcher.
49 class ShelfTooltipManager::ShelfTooltipBubble 57 class ShelfTooltipManager::ShelfTooltipBubble
50 : public views::BubbleDialogDelegateView { 58 : public views::BubbleDialogDelegateView {
51 public: 59 public:
52 ShelfTooltipBubble(views::View* anchor, 60 ShelfTooltipBubble(views::View* anchor,
53 views::BubbleBorder::Arrow arrow, 61 views::BubbleBorder::Arrow arrow,
54 const base::string16& text) 62 const base::string16& text)
55 : views::BubbleDialogDelegateView(anchor, arrow) { 63 : views::BubbleDialogDelegateView(anchor, arrow) {
56 gfx::Insets insets = 64 gfx::Insets insets =
James Cook 2016/07/25 17:01:08 nit: Just gfx::Insets insets(value, value);
varkha 2016/07/26 19:20:00 Done.
57 gfx::Insets(kArrowOffsetTopBottom, kArrowOffsetLeftRight); 65 gfx::Insets(kArrowTopBottomOffset, kArrowLeftRightOffset);
58 // Adjust the anchor location for asymmetrical borders of shelf item. 66 // Adjust the anchor location for asymmetrical borders of shelf item.
59 if (anchor->border()) 67 if (anchor->border())
60 insets += anchor->border()->GetInsets(); 68 insets += anchor->border()->GetInsets();
61 69
62 set_anchor_view_insets(insets); 70 set_anchor_view_insets(insets);
63 set_close_on_deactivate(false); 71 set_close_on_deactivate(false);
64 set_can_activate(false); 72 set_can_activate(false);
65 set_accept_events(false); 73 set_accept_events(false);
66 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin)); 74 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin));
67 set_shadow(views::BubbleBorder::SMALL_SHADOW); 75 set_shadow(views::BubbleBorder::NO_ASSETS);
68 SetLayoutManager(new views::FillLayout()); 76 SetLayoutManager(new views::FillLayout());
69 // The anchor may not have the widget in tests. 77 // The anchor may not have the widget in tests.
70 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { 78 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) {
71 set_parent_window(ash::Shell::GetContainer( 79 set_parent_window(ash::Shell::GetContainer(
72 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), 80 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(),
73 ash::kShellWindowId_SettingBubbleContainer)); 81 ash::kShellWindowId_SettingBubbleContainer));
74 } 82 }
75 views::Label* label = new views::Label(text); 83 views::Label* label = new views::Label(text);
76 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 84 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
77 label->SetEnabledColor(kTooltipTextColor); 85 ui::NativeTheme* theme = anchor->GetWidget()->GetNativeTheme();
86 label->SetEnabledColor(
87 theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText));
James Cook 2016/07/25 17:01:08 Just for my knowledge, is this the usual way of ge
varkha 2016/07/26 19:20:00 In this case we want the color to match the top ch
88 SkColor background_color =
89 theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
90 set_color(background_color);
91 label->SetBackgroundColor(background_color);
78 AddChildView(label); 92 AddChildView(label);
79 views::BubbleDialogDelegateView::CreateBubble(this); 93 views::BubbleDialogDelegateView::CreateBubble(this);
94 // The bubble border has its own background so the background created by the
95 // BubbleDialogDelegateView is redundant and would cause extra opacity.
96 set_background(nullptr);
97 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
98 SetBorderInteriorThickness(kBorderInteriorThickness);
80 } 99 }
81 100
82 private: 101 private:
83 // BubbleDialogDelegateView overrides: 102 // BubbleDialogDelegateView overrides:
84 gfx::Size GetPreferredSize() const override { 103 gfx::Size GetPreferredSize() const override {
85 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); 104 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize();
105 const int kTooltipMinHeight = kTooltipHeight - 2 * kTooltipTopBottomMargin;
86 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), 106 return gfx::Size(std::min(size.width(), kTooltipMaxWidth),
87 std::max(size.height(), kTooltipMinHeight)); 107 std::max(size.height(), kTooltipMinHeight));
88 } 108 }
89 109
90 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } 110 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
91 111
92 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); 112 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble);
93 }; 113 };
94 114
95 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) 115 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); 270 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr()));
251 } 271 }
252 } 272 }
253 273
254 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { 274 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) {
255 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && 275 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) &&
256 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); 276 shelf_layout_manager_ && shelf_layout_manager_->IsVisible();
257 } 277 }
258 278
259 } // namespace ash 279 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/views/bubble/bubble_border.h » ('j') | ui/views/bubble/bubble_border.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698