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

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 (nits) Created 4 years, 4 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') | no next file with comments »
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.
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(kArrowTopBottomOffset, kArrowLeftRightOffset);
57 gfx::Insets(kArrowOffsetTopBottom, kArrowOffsetLeftRight);
58 // Adjust the anchor location for asymmetrical borders of shelf item. 65 // Adjust the anchor location for asymmetrical borders of shelf item.
59 if (anchor->border()) 66 if (anchor->border())
60 insets += anchor->border()->GetInsets(); 67 insets += anchor->border()->GetInsets();
61 68
62 set_anchor_view_insets(insets); 69 set_anchor_view_insets(insets);
63 set_close_on_deactivate(false); 70 set_close_on_deactivate(false);
64 set_can_activate(false); 71 set_can_activate(false);
65 set_accept_events(false); 72 set_accept_events(false);
66 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin)); 73 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin));
67 set_shadow(views::BubbleBorder::SMALL_SHADOW); 74 set_shadow(views::BubbleBorder::NO_ASSETS);
68 SetLayoutManager(new views::FillLayout()); 75 SetLayoutManager(new views::FillLayout());
69 // The anchor may not have the widget in tests. 76 // The anchor may not have the widget in tests.
70 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { 77 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) {
71 set_parent_window(ash::Shell::GetContainer( 78 set_parent_window(ash::Shell::GetContainer(
72 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), 79 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(),
73 ash::kShellWindowId_SettingBubbleContainer)); 80 ash::kShellWindowId_SettingBubbleContainer));
74 } 81 }
75 views::Label* label = new views::Label(text); 82 views::Label* label = new views::Label(text);
76 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 83 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
77 label->SetEnabledColor(kTooltipTextColor); 84 ui::NativeTheme* theme = anchor->GetWidget()->GetNativeTheme();
85 label->SetEnabledColor(
86 theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText));
87 SkColor background_color =
88 theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
89 set_color(background_color);
90 label->SetBackgroundColor(background_color);
78 AddChildView(label); 91 AddChildView(label);
79 views::BubbleDialogDelegateView::CreateBubble(this); 92 views::BubbleDialogDelegateView::CreateBubble(this);
93 // The bubble border has its own background so the background created by the
94 // BubbleDialogDelegateView is redundant and would cause extra opacity.
95 set_background(nullptr);
96 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT);
97 SetBorderInteriorThickness(kBorderInteriorThickness);
80 } 98 }
81 99
82 private: 100 private:
83 // BubbleDialogDelegateView overrides: 101 // BubbleDialogDelegateView overrides:
84 gfx::Size GetPreferredSize() const override { 102 gfx::Size GetPreferredSize() const override {
85 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); 103 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize();
104 const int kTooltipMinHeight = kTooltipHeight - 2 * kTooltipTopBottomMargin;
86 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), 105 return gfx::Size(std::min(size.width(), kTooltipMaxWidth),
87 std::max(size.height(), kTooltipMinHeight)); 106 std::max(size.height(), kTooltipMinHeight));
88 } 107 }
89 108
90 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } 109 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
91 110
92 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); 111 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble);
93 }; 112 };
94 113
95 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) 114 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())); 269 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr()));
251 } 270 }
252 } 271 }
253 272
254 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { 273 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) {
255 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && 274 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) &&
256 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); 275 shelf_layout_manager_ && shelf_layout_manager_->IsVisible();
257 } 276 }
258 277
259 } // namespace ash 278 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/views/bubble/bubble_border.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698