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

Side by Side Diff: ui/views/corewm/tooltip_aura.cc

Issue 2164783002: [md] Updates aura tooltip colors and padding to MD (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [md] Updates aura tooltip colors and padding to MD (disable subpixel anti-aliasing for transparent … 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 | « ui/views/corewm/DEPS ('k') | no next file » | 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 "ui/views/corewm/tooltip_aura.h" 5 #include "ui/views/corewm/tooltip_aura.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
11 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
12 #include "ui/base/material_design/material_design_controller.h"
12 #include "ui/display/display.h" 13 #include "ui/display/display.h"
13 #include "ui/display/screen.h" 14 #include "ui/display/screen.h"
14 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/render_text.h" 16 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/text_elider.h" 17 #include "ui/gfx/text_elider.h"
17 #include "ui/gfx/text_utils.h" 18 #include "ui/gfx/text_utils.h"
18 #include "ui/native_theme/native_theme.h" 19 #include "ui/native_theme/native_theme.h"
19 #include "ui/views/background.h" 20 #include "ui/views/background.h"
20 #include "ui/views/border.h" 21 #include "ui/views/border.h"
22 #include "ui/views/painter.h"
21 #include "ui/views/view.h" 23 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
23 25
24 namespace { 26 namespace {
25 27
26 // Max visual tooltip width. If a tooltip is greater than this width, it will 28 // Max visual tooltip width. If a tooltip is greater than this width, it will
27 // be wrapped. 29 // be wrapped.
28 const int kTooltipMaxWidthPixels = 400; 30 const int kTooltipMaxWidthPixels = 400;
29 31
32 // Corner radius of tooltip background used with Material Design.
33 const float kTooltipCornerRadius = 2.f;
34
30 // FIXME: get cursor offset from actual cursor size. 35 // FIXME: get cursor offset from actual cursor size.
31 const int kCursorOffsetX = 10; 36 const int kCursorOffsetX = 10;
32 const int kCursorOffsetY = 15; 37 const int kCursorOffsetY = 15;
33 38
34 // Creates a widget of type TYPE_TOOLTIP 39 // Creates a widget of type TYPE_TOOLTIP
35 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { 40 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) {
36 views::Widget* widget = new views::Widget; 41 views::Widget* widget = new views::Widget;
37 views::Widget::InitParams params; 42 views::Widget::InitParams params;
38 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get 43 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get
39 // auto-parented to the right container. 44 // auto-parented to the right container.
40 params.type = views::Widget::InitParams::TYPE_TOOLTIP; 45 params.type = views::Widget::InitParams::TYPE_TOOLTIP;
41 params.context = tooltip_window; 46 params.context = tooltip_window;
42 DCHECK(params.context); 47 DCHECK(params.context);
43 params.keep_on_top = true; 48 params.keep_on_top = true;
44 params.accept_events = false; 49 params.accept_events = false;
50 if (ui::MaterialDesignController::IsModeMaterial()) {
51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
52 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
53 }
45 widget->Init(params); 54 widget->Init(params);
46 return widget; 55 return widget;
47 } 56 }
48 57
49 } // namespace 58 } // namespace
50 59
51 namespace views { 60 namespace views {
52 namespace corewm { 61 namespace corewm {
53 62
54 // TODO(oshima): Consider to use views::Label. 63 // TODO(oshima): Consider to use views::Label.
55 class TooltipAura::TooltipView : public views::View { 64 class TooltipAura::TooltipView : public views::View {
56 public: 65 public:
57 TooltipView() 66 TooltipView()
58 : render_text_(gfx::RenderText::CreateInstance()), 67 : render_text_(gfx::RenderText::CreateInstance()),
59 max_width_(0) { 68 max_width_(0) {
60 const int kHorizontalPadding = 3; 69 const bool material = ui::MaterialDesignController::IsModeMaterial();
61 const int kVerticalPadding = 2; 70 const int kHorizontalPadding = material ? 8 : 3;
62 SetBorder(Border::CreateEmptyBorder( 71 const int kVerticalPaddingTop = material ? 4 : 2;
63 kVerticalPadding, kHorizontalPadding, 72 const int kVerticalPaddingBottom = material ? 5 : kVerticalPaddingTop;
64 kVerticalPadding, kHorizontalPadding)); 73 SetBorder(Border::CreateEmptyBorder(kVerticalPaddingTop, kHorizontalPadding,
74 kVerticalPaddingBottom,
75 kHorizontalPadding));
65 76
66 set_owned_by_client(); 77 set_owned_by_client();
67 render_text_->SetWordWrapBehavior(gfx::WRAP_LONG_WORDS); 78 render_text_->SetWordWrapBehavior(gfx::WRAP_LONG_WORDS);
68 render_text_->SetMultiline(true); 79 render_text_->SetMultiline(true);
69 80
70 ResetDisplayRect(); 81 ResetDisplayRect();
71 } 82 }
72 83
73 ~TooltipView() override {} 84 ~TooltipView() override {}
74 85
(...skipping 25 matching lines...) Expand all
100 void SetText(const base::string16& text) { 111 void SetText(const base::string16& text) {
101 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); 112 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD);
102 render_text_->SetText(text); 113 render_text_->SetText(text);
103 SchedulePaint(); 114 SchedulePaint();
104 } 115 }
105 116
106 void SetForegroundColor(SkColor color) { 117 void SetForegroundColor(SkColor color) {
107 render_text_->SetColor(color); 118 render_text_->SetColor(color);
108 } 119 }
109 120
121 void SetBackgroundColor(SkColor background_color) {
122 views::Background* background =
123 ui::MaterialDesignController::IsModeMaterial()
124 ? views::Background::CreateBackgroundPainter(
125 true, views::Painter::CreateSolidRoundRectPainter(
126 background_color, kTooltipCornerRadius))
127 : views::Background::CreateSolidBackground(background_color);
128 set_background(background);
129 // Force the text color to be readable when |background_color| is not
130 // opaque.
131 render_text_->set_subpixel_rendering_suppressed(
132 SkColorGetA(background_color) != 0xFF);
133 }
134
110 void SetMaxWidth(int width) { 135 void SetMaxWidth(int width) {
111 max_width_ = width; 136 max_width_ = width;
112 ResetDisplayRect(); 137 ResetDisplayRect();
113 } 138 }
114 139
115 private: 140 private:
116 void ResetDisplayRect() { 141 void ResetDisplayRect() {
117 gfx::Insets insets = border()->GetInsets(); 142 gfx::Insets insets = border()->GetInsets();
118 int max_text_width = max_width_ - insets.width(); 143 int max_text_width = max_width_ - insets.width();
119 render_text_->SetDisplayRect(gfx::Rect(0, 0, max_text_width, 100000)); 144 render_text_->SetDisplayRect(gfx::Rect(0, 0, max_text_width, 100000));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 206
182 if (!widget_) { 207 if (!widget_) {
183 widget_ = CreateTooltipWidget(tooltip_window_); 208 widget_ = CreateTooltipWidget(tooltip_window_);
184 widget_->SetContentsView(tooltip_view_.get()); 209 widget_->SetContentsView(tooltip_view_.get());
185 widget_->AddObserver(this); 210 widget_->AddObserver(this);
186 } 211 }
187 212
188 SetTooltipBounds(location, tooltip_view_->GetPreferredSize()); 213 SetTooltipBounds(location, tooltip_view_->GetPreferredSize());
189 214
190 ui::NativeTheme* native_theme = widget_->GetNativeTheme(); 215 ui::NativeTheme* native_theme = widget_->GetNativeTheme();
191 tooltip_view_->set_background( 216 tooltip_view_->SetBackgroundColor(native_theme->GetSystemColor(
192 views::Background::CreateSolidBackground( 217 ui::NativeTheme::kColorId_TooltipBackground));
193 native_theme->GetSystemColor(
194 ui::NativeTheme::kColorId_TooltipBackground)));
195 tooltip_view_->SetForegroundColor(native_theme->GetSystemColor( 218 tooltip_view_->SetForegroundColor(native_theme->GetSystemColor(
196 ui::NativeTheme::kColorId_TooltipText)); 219 ui::NativeTheme::kColorId_TooltipText));
197 } 220 }
198 221
199 void TooltipAura::Show() { 222 void TooltipAura::Show() {
200 if (widget_) { 223 if (widget_) {
201 widget_->Show(); 224 widget_->Show();
202 widget_->StackAtTop(); 225 widget_->StackAtTop();
203 } 226 }
204 } 227 }
205 228
206 void TooltipAura::Hide() { 229 void TooltipAura::Hide() {
207 tooltip_window_ = NULL; 230 tooltip_window_ = NULL;
208 if (widget_) 231 if (widget_)
209 widget_->Hide(); 232 widget_->Hide();
210 } 233 }
211 234
212 bool TooltipAura::IsVisible() { 235 bool TooltipAura::IsVisible() {
213 return widget_ && widget_->IsVisible(); 236 return widget_ && widget_->IsVisible();
214 } 237 }
215 238
216 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { 239 void TooltipAura::OnWidgetDestroying(views::Widget* widget) {
217 DCHECK_EQ(widget_, widget); 240 DCHECK_EQ(widget_, widget);
218 widget_ = NULL; 241 widget_ = NULL;
219 tooltip_window_ = NULL; 242 tooltip_window_ = NULL;
220 } 243 }
221 244
222 } // namespace corewm 245 } // namespace corewm
223 } // namespace views 246 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698