| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/screen.h" | 12 #include "ui/gfx/screen.h" |
| 13 #include "ui/gfx/text_elider.h" | 13 #include "ui/gfx/text_elider.h" |
| 14 #include "ui/gfx/text_utils.h" | 14 #include "ui/gfx/text_utils.h" |
| 15 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/views/background.h" | 16 #include "ui/views/background.h" |
| 16 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const SkColor kTooltipBackground = 0xFFFFFFCC; | |
| 22 const int kTooltipHorizontalPadding = 3; | 22 const int kTooltipHorizontalPadding = 3; |
| 23 | 23 |
| 24 // Max visual tooltip width. If a tooltip is greater than this width, it will | 24 // Max visual tooltip width. If a tooltip is greater than this width, it will |
| 25 // be wrapped. | 25 // be wrapped. |
| 26 const int kTooltipMaxWidthPixels = 400; | 26 const int kTooltipMaxWidthPixels = 400; |
| 27 | 27 |
| 28 const size_t kMaxLines = 10; | 28 const size_t kMaxLines = 10; |
| 29 | 29 |
| 30 // TODO(derat): This padding is needed on Chrome OS devices but seems excessive | 30 // TODO(derat): This padding is needed on Chrome OS devices but seems excessive |
| 31 // when running the same binary on a Linux workstation; presumably there's a | 31 // when running the same binary on a Linux workstation; presumably there's a |
| (...skipping 21 matching lines...) Expand all Loading... |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 namespace views { | 56 namespace views { |
| 57 namespace corewm { | 57 namespace corewm { |
| 58 | 58 |
| 59 TooltipAura::TooltipAura(gfx::ScreenType screen_type) | 59 TooltipAura::TooltipAura(gfx::ScreenType screen_type) |
| 60 : screen_type_(screen_type), | 60 : screen_type_(screen_type), |
| 61 widget_(NULL), | 61 widget_(NULL), |
| 62 tooltip_window_(NULL) { | 62 tooltip_window_(NULL) { |
| 63 label_.set_background( | |
| 64 views::Background::CreateSolidBackground(kTooltipBackground)); | |
| 65 label_.set_owned_by_client(); | 63 label_.set_owned_by_client(); |
| 66 label_.SetMultiLine(true); | 64 label_.SetMultiLine(true); |
| 67 } | 65 } |
| 68 | 66 |
| 69 TooltipAura::~TooltipAura() { | 67 TooltipAura::~TooltipAura() { |
| 70 DestroyWidget(); | 68 DestroyWidget(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 // static | 71 // static |
| 74 void TooltipAura::TrimTooltipToFit(const gfx::FontList& font_list, | 72 void TooltipAura::TrimTooltipToFit(const gfx::FontList& font_list, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 base::string16 trimmed_text(tooltip_text); | 225 base::string16 trimmed_text(tooltip_text); |
| 228 TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text, | 226 TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text, |
| 229 &max_width, &line_count); | 227 &max_width, &line_count); |
| 230 label_.SetText(trimmed_text); | 228 label_.SetText(trimmed_text); |
| 231 | 229 |
| 232 int width = max_width + 2 * kTooltipHorizontalPadding; | 230 int width = max_width + 2 * kTooltipHorizontalPadding; |
| 233 int height = label_.GetHeightForWidth(max_width) + | 231 int height = label_.GetHeightForWidth(max_width) + |
| 234 2 * kTooltipVerticalPadding; | 232 2 * kTooltipVerticalPadding; |
| 235 CreateWidget(); | 233 CreateWidget(); |
| 236 SetTooltipBounds(location, width, height); | 234 SetTooltipBounds(location, width, height); |
| 235 |
| 236 label_.set_background( |
| 237 views::Background::CreateSolidBackground( |
| 238 widget_->GetNativeTheme()->GetSystemColor( |
| 239 ui::NativeTheme::kColorId_TooltipBackground))); |
| 237 } | 240 } |
| 238 | 241 |
| 239 void TooltipAura::Show() { | 242 void TooltipAura::Show() { |
| 240 if (widget_) | 243 if (widget_) |
| 241 widget_->Show(); | 244 widget_->Show(); |
| 242 } | 245 } |
| 243 | 246 |
| 244 void TooltipAura::Hide() { | 247 void TooltipAura::Hide() { |
| 245 tooltip_window_ = NULL; | 248 tooltip_window_ = NULL; |
| 246 if (widget_) | 249 if (widget_) |
| 247 widget_->Hide(); | 250 widget_->Hide(); |
| 248 } | 251 } |
| 249 | 252 |
| 250 bool TooltipAura::IsVisible() { | 253 bool TooltipAura::IsVisible() { |
| 251 return widget_ && widget_->IsVisible(); | 254 return widget_ && widget_->IsVisible(); |
| 252 } | 255 } |
| 253 | 256 |
| 254 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { | 257 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { |
| 255 DCHECK_EQ(widget_, widget); | 258 DCHECK_EQ(widget_, widget); |
| 256 widget_ = NULL; | 259 widget_ = NULL; |
| 257 tooltip_window_ = NULL; | 260 tooltip_window_ = NULL; |
| 258 } | 261 } |
| 259 | 262 |
| 260 } // namespace corewm | 263 } // namespace corewm |
| 261 } // namespace views | 264 } // namespace views |
| OLD | NEW |