| OLD | NEW |
| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
| 23 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // 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 |
| 29 // be wrapped. | 29 // be wrapped. |
| 30 const int kTooltipMaxWidthPixels = 400; | 30 const int kTooltipMaxWidthPixels = 400; |
| 31 | 31 |
| 32 // Corner radius of tooltip background used with Material Design. | |
| 33 const float kTooltipCornerRadius = 2.f; | |
| 34 | |
| 35 // FIXME: get cursor offset from actual cursor size. | 32 // FIXME: get cursor offset from actual cursor size. |
| 36 const int kCursorOffsetX = 10; | 33 const int kCursorOffsetX = 10; |
| 37 const int kCursorOffsetY = 15; | 34 const int kCursorOffsetY = 15; |
| 38 | 35 |
| 36 // TODO(varkha): Update if native widget can be transparent on Linux. |
| 37 bool CanUseTranslucentTooltipWidget() { |
| 38 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 39 return false; |
| 40 #else |
| 41 return ui::MaterialDesignController::IsModeMaterial(); |
| 42 #endif |
| 43 } |
| 44 |
| 39 // Creates a widget of type TYPE_TOOLTIP | 45 // Creates a widget of type TYPE_TOOLTIP |
| 40 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { | 46 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { |
| 41 views::Widget* widget = new views::Widget; | 47 views::Widget* widget = new views::Widget; |
| 42 views::Widget::InitParams params; | 48 views::Widget::InitParams params; |
| 43 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get | 49 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get |
| 44 // auto-parented to the right container. | 50 // auto-parented to the right container. |
| 45 params.type = views::Widget::InitParams::TYPE_TOOLTIP; | 51 params.type = views::Widget::InitParams::TYPE_TOOLTIP; |
| 46 params.context = tooltip_window; | 52 params.context = tooltip_window; |
| 47 DCHECK(params.context); | 53 DCHECK(params.context); |
| 48 params.keep_on_top = true; | 54 params.keep_on_top = true; |
| 49 params.accept_events = false; | 55 params.accept_events = false; |
| 50 if (ui::MaterialDesignController::IsModeMaterial()) { | 56 if (CanUseTranslucentTooltipWidget()) |
| 51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 57 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 58 if (ui::MaterialDesignController::IsModeMaterial()) |
| 52 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; | 59 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; |
| 53 } | |
| 54 widget->Init(params); | 60 widget->Init(params); |
| 55 return widget; | 61 return widget; |
| 56 } | 62 } |
| 57 | 63 |
| 58 } // namespace | 64 } // namespace |
| 59 | 65 |
| 60 namespace views { | 66 namespace views { |
| 61 namespace corewm { | 67 namespace corewm { |
| 62 | 68 |
| 63 // TODO(oshima): Consider to use views::Label. | 69 // TODO(oshima): Consider to use views::Label. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | 118 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
| 113 render_text_->SetText(text); | 119 render_text_->SetText(text); |
| 114 SchedulePaint(); | 120 SchedulePaint(); |
| 115 } | 121 } |
| 116 | 122 |
| 117 void SetForegroundColor(SkColor color) { | 123 void SetForegroundColor(SkColor color) { |
| 118 render_text_->SetColor(color); | 124 render_text_->SetColor(color); |
| 119 } | 125 } |
| 120 | 126 |
| 121 void SetBackgroundColor(SkColor background_color) { | 127 void SetBackgroundColor(SkColor background_color) { |
| 128 // Corner radius of tooltip background used with Material Design. |
| 129 const float kTooltipCornerRadius = 2.f; |
| 122 views::Background* background = | 130 views::Background* background = |
| 123 ui::MaterialDesignController::IsModeMaterial() | 131 CanUseTranslucentTooltipWidget() |
| 124 ? views::Background::CreateBackgroundPainter( | 132 ? views::Background::CreateBackgroundPainter( |
| 125 true, views::Painter::CreateSolidRoundRectPainter( | 133 true, views::Painter::CreateSolidRoundRectPainter( |
| 126 background_color, kTooltipCornerRadius)) | 134 background_color, kTooltipCornerRadius)) |
| 127 : views::Background::CreateSolidBackground(background_color); | 135 : views::Background::CreateSolidBackground(background_color); |
| 128 set_background(background); | 136 set_background(background); |
| 129 // Force the text color to be readable when |background_color| is not | 137 // Force the text color to be readable when |background_color| is not |
| 130 // opaque. | 138 // opaque. |
| 131 render_text_->set_subpixel_rendering_suppressed( | 139 render_text_->set_subpixel_rendering_suppressed( |
| 132 SkColorGetA(background_color) != 0xFF); | 140 SkColorGetA(background_color) != 0xFF); |
| 133 } | 141 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 245 } |
| 238 | 246 |
| 239 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { | 247 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { |
| 240 DCHECK_EQ(widget_, widget); | 248 DCHECK_EQ(widget_, widget); |
| 241 widget_ = NULL; | 249 widget_ = NULL; |
| 242 tooltip_window_ = NULL; | 250 tooltip_window_ = NULL; |
| 243 } | 251 } |
| 244 | 252 |
| 245 } // namespace corewm | 253 } // namespace corewm |
| 246 } // namespace views | 254 } // namespace views |
| OLD | NEW |