Chromium Code Reviews| 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 |
| 39 // Creates a widget of type TYPE_TOOLTIP | 36 // Creates a widget of type TYPE_TOOLTIP |
| 40 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { | 37 views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) { |
| 41 views::Widget* widget = new views::Widget; | 38 views::Widget* widget = new views::Widget; |
| 42 views::Widget::InitParams params; | 39 views::Widget::InitParams params; |
| 43 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get | 40 // For aura, since we set the type to TYPE_TOOLTIP, the widget will get |
| 44 // auto-parented to the right container. | 41 // auto-parented to the right container. |
| 45 params.type = views::Widget::InitParams::TYPE_TOOLTIP; | 42 params.type = views::Widget::InitParams::TYPE_TOOLTIP; |
| 46 params.context = tooltip_window; | 43 params.context = tooltip_window; |
| 47 DCHECK(params.context); | 44 DCHECK(params.context); |
| 48 params.keep_on_top = true; | 45 params.keep_on_top = true; |
| 49 params.accept_events = false; | 46 params.accept_events = false; |
| 50 if (ui::MaterialDesignController::IsModeMaterial()) { | 47 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 48 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 52 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; | 49 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE; |
| 53 } | 50 } |
|
sadrul
2016/07/23 01:08:05
I think we shouldn't set the opacity to translucen
varkha
2016/07/23 01:22:17
Done.
| |
| 54 widget->Init(params); | 51 widget->Init(params); |
| 55 return widget; | 52 return widget; |
| 56 } | 53 } |
| 57 | 54 |
| 58 } // namespace | 55 } // namespace |
| 59 | 56 |
| 60 namespace views { | 57 namespace views { |
| 61 namespace corewm { | 58 namespace corewm { |
| 62 | 59 |
| 63 // TODO(oshima): Consider to use views::Label. | 60 // 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); | 109 render_text_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
| 113 render_text_->SetText(text); | 110 render_text_->SetText(text); |
| 114 SchedulePaint(); | 111 SchedulePaint(); |
| 115 } | 112 } |
| 116 | 113 |
| 117 void SetForegroundColor(SkColor color) { | 114 void SetForegroundColor(SkColor color) { |
| 118 render_text_->SetColor(color); | 115 render_text_->SetColor(color); |
| 119 } | 116 } |
| 120 | 117 |
| 121 void SetBackgroundColor(SkColor background_color) { | 118 void SetBackgroundColor(SkColor background_color) { |
| 119 // TODO(varkha): Update if native widget can be transparent on Linux. | |
| 120 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 122 views::Background* background = | 121 views::Background* background = |
| 123 ui::MaterialDesignController::IsModeMaterial() | 122 views::Background::CreateSolidBackground(background_color); |
| 123 #else | |
| 124 // Corner radius of tooltip background used with Material Design. | |
| 125 const float kTooltipCornerRadius = 2.f; | |
| 126 const bool material = ui::MaterialDesignController::IsModeMaterial(); | |
| 127 views::Background* background = | |
| 128 material | |
| 124 ? views::Background::CreateBackgroundPainter( | 129 ? views::Background::CreateBackgroundPainter( |
| 125 true, views::Painter::CreateSolidRoundRectPainter( | 130 true, views::Painter::CreateSolidRoundRectPainter( |
| 126 background_color, kTooltipCornerRadius)) | 131 background_color, kTooltipCornerRadius)) |
| 127 : views::Background::CreateSolidBackground(background_color); | 132 : views::Background::CreateSolidBackground(background_color); |
| 133 #endif | |
| 128 set_background(background); | 134 set_background(background); |
| 129 // Force the text color to be readable when |background_color| is not | 135 // Force the text color to be readable when |background_color| is not |
| 130 // opaque. | 136 // opaque. |
| 131 render_text_->set_subpixel_rendering_suppressed( | 137 render_text_->set_subpixel_rendering_suppressed( |
| 132 SkColorGetA(background_color) != 0xFF); | 138 SkColorGetA(background_color) != 0xFF); |
| 133 } | 139 } |
| 134 | 140 |
| 135 void SetMaxWidth(int width) { | 141 void SetMaxWidth(int width) { |
| 136 max_width_ = width; | 142 max_width_ = width; |
| 137 ResetDisplayRect(); | 143 ResetDisplayRect(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 243 } |
| 238 | 244 |
| 239 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { | 245 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { |
| 240 DCHECK_EQ(widget_, widget); | 246 DCHECK_EQ(widget_, widget); |
| 241 widget_ = NULL; | 247 widget_ = NULL; |
| 242 tooltip_window_ = NULL; | 248 tooltip_window_ = NULL; |
| 243 } | 249 } |
| 244 | 250 |
| 245 } // namespace corewm | 251 } // namespace corewm |
| 246 } // namespace views | 252 } // namespace views |
| OLD | NEW |