summaryrefslogtreecommitdiffstats
path: root/chromium/ui/views/corewm/tooltip_aura.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/corewm/tooltip_aura.cc')
-rw-r--r--chromium/ui/views/corewm/tooltip_aura.cc130
1 files changed, 48 insertions, 82 deletions
diff --git a/chromium/ui/views/corewm/tooltip_aura.cc b/chromium/ui/views/corewm/tooltip_aura.cc
index 7c11bd80bbc..f9f41b93722 100644
--- a/chromium/ui/views/corewm/tooltip_aura.cc
+++ b/chromium/ui/views/corewm/tooltip_aura.cc
@@ -4,23 +4,20 @@
#include "ui/views/corewm/tooltip_aura.h"
-#include "base/command_line.h"
#include "base/strings/string_split.h"
-#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/text_elider.h"
+#include "ui/gfx/text_utils.h"
+#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
-#include "ui/views/corewm/corewm_switches.h"
#include "ui/views/widget/widget.h"
namespace {
-const SkColor kTooltipBackground = 0xFFFFFFCC;
-const SkColor kTooltipBorder = 0xFF646450;
-const int kTooltipBorderWidth = 1;
const int kTooltipHorizontalPadding = 3;
// Max visual tooltip width. If a tooltip is greater than this width, it will
@@ -53,13 +50,6 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) {
return widget;
}
-gfx::Font GetDefaultFont() {
- // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
- // out a way to merge.
- return ui::ResourceBundle::GetSharedInstance().GetFont(
- ui::ResourceBundle::BaseFont);
-}
-
} // namespace
namespace views {
@@ -69,13 +59,6 @@ TooltipAura::TooltipAura(gfx::ScreenType screen_type)
: screen_type_(screen_type),
widget_(NULL),
tooltip_window_(NULL) {
- label_.set_background(
- views::Background::CreateSolidBackground(kTooltipBackground));
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) {
- label_.set_border(
- views::Border::CreateSolidBorder(kTooltipBorderWidth,
- kTooltipBorder));
- }
label_.set_owned_by_client();
label_.SetMultiLine(true);
}
@@ -85,8 +68,9 @@ TooltipAura::~TooltipAura() {
}
// static
-void TooltipAura::TrimTooltipToFit(int max_width,
- string16* text,
+void TooltipAura::TrimTooltipToFit(const gfx::FontList& font_list,
+ int max_width,
+ base::string16* text,
int* width,
int* line_count) {
*width = 0;
@@ -95,27 +79,26 @@ void TooltipAura::TrimTooltipToFit(int max_width,
// Determine the available width for the tooltip.
int available_width = std::min(kTooltipMaxWidthPixels, max_width);
- std::vector<string16> lines;
+ std::vector<base::string16> lines;
base::SplitString(*text, '\n', &lines);
- std::vector<string16> result_lines;
+ std::vector<base::string16> result_lines;
// Format each line to fit.
- gfx::Font font = GetDefaultFont();
- for (std::vector<string16>::iterator l = lines.begin(); l != lines.end();
- ++l) {
+ for (std::vector<base::string16>::iterator l = lines.begin();
+ l != lines.end(); ++l) {
// We break the line at word boundaries, then stuff as many words as we can
// in the available width to the current line, and move the remaining words
// to a new line.
- std::vector<string16> words;
+ std::vector<base::string16> words;
base::SplitStringDontTrim(*l, ' ', &words);
int current_width = 0;
- string16 line;
- for (std::vector<string16>::iterator w = words.begin(); w != words.end();
- ++w) {
- string16 word = *w;
+ base::string16 line;
+ for (std::vector<base::string16>::iterator w = words.begin();
+ w != words.end(); ++w) {
+ base::string16 word = *w;
if (w + 1 != words.end())
word.push_back(' ');
- int word_width = font.GetStringWidth(word);
+ int word_width = gfx::GetStringWidth(word, font_list);
if (current_width + word_width > available_width) {
// Current width will exceed the available width. Must start a new line.
if (!line.empty())
@@ -139,19 +122,19 @@ void TooltipAura::TrimTooltipToFit(int max_width,
*line_count = result_lines.size();
// Flatten the result.
- string16 result;
- for (std::vector<string16>::iterator l = result_lines.begin();
+ base::string16 result;
+ for (std::vector<base::string16>::iterator l = result_lines.begin();
l != result_lines.end(); ++l) {
if (!result.empty())
result.push_back('\n');
- int line_width = font.GetStringWidth(*l);
+ int line_width = gfx::GetStringWidth(*l, font_list);
// Since we only break at word boundaries, it could happen that due to some
// very long word, line_width is greater than the available_width. In such
// case, we simply truncate at available_width and add ellipses at the end.
if (line_width > available_width) {
*width = available_width;
- result.append(gfx::ElideText(*l, font, available_width,
- gfx::ELIDE_AT_END));
+ result.append(gfx::ElideText(*l, font_list, available_width,
+ gfx::ELIDE_TAIL));
} else {
*width = std::max(*width, line_width);
result.append(*l);
@@ -163,25 +146,9 @@ void TooltipAura::TrimTooltipToFit(int max_width,
int TooltipAura::GetMaxWidth(const gfx::Point& location) const {
// TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
// out a way to merge.
- gfx::Rect display_bounds = GetBoundsForTooltip(location);
- return (display_bounds.width() + 1) / 2;
-}
-
-gfx::Rect TooltipAura::GetBoundsForTooltip(
- const gfx::Point& origin) const {
- DCHECK(tooltip_window_);
- gfx::Rect widget_bounds;
- // For Desktop aura we constrain the tooltip to the bounds of the Widget
- // (which comes from the RootWindow).
- if (screen_type_ == gfx::SCREEN_TYPE_NATIVE &&
- gfx::SCREEN_TYPE_NATIVE != gfx::SCREEN_TYPE_ALTERNATE) {
- widget_bounds = tooltip_window_->GetDispatcher()->host()->GetBounds();
- }
gfx::Screen* screen = gfx::Screen::GetScreenByType(screen_type_);
- gfx::Rect bounds(screen->GetDisplayNearestPoint(origin).bounds());
- if (!widget_bounds.IsEmpty())
- bounds.Intersect(widget_bounds);
- return bounds;
+ gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds());
+ return (display_bounds.width() + 1) / 2;
}
void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
@@ -191,7 +158,8 @@ void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
tooltip_height);
tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
- gfx::Rect display_bounds = GetBoundsForTooltip(mouse_pos);
+ gfx::Screen* screen = gfx::Screen::GetScreenByType(screen_type_);
+ gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds());
// If tooltip is out of bounds on the x axis, we simply shift it
// horizontally by the offset.
@@ -209,22 +177,6 @@ void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
widget_->SetBounds(tooltip_rect);
}
-void TooltipAura::CreateWidget() {
- if (widget_) {
- // If the window for which the tooltip is being displayed changes and if the
- // tooltip window and the tooltip widget belong to different rootwindows
- // then we need to recreate the tooltip widget under the active root window
- // hierarchy to get it to display.
- if (widget_->GetNativeWindow()->GetRootWindow() ==
- tooltip_window_->GetRootWindow())
- return;
- DestroyWidget();
- }
- widget_ = CreateTooltipWidget(tooltip_window_);
- widget_->SetContentsView(&label_);
- widget_->AddObserver(this);
-}
-
void TooltipAura::DestroyWidget() {
if (widget_) {
widget_->RemoveObserver(this);
@@ -234,29 +186,43 @@ void TooltipAura::DestroyWidget() {
}
void TooltipAura::SetText(aura::Window* window,
- const string16& tooltip_text,
+ const base::string16& tooltip_text,
const gfx::Point& location) {
tooltip_window_ = window;
int max_width, line_count;
- string16 trimmed_text(tooltip_text);
- TrimTooltipToFit(
- GetMaxWidth(location), &trimmed_text, &max_width, &line_count);
+ base::string16 trimmed_text(tooltip_text);
+ TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text,
+ &max_width, &line_count);
label_.SetText(trimmed_text);
int width = max_width + 2 * kTooltipHorizontalPadding;
int height = label_.GetHeightForWidth(max_width) +
2 * kTooltipVerticalPadding;
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoDropShadows)) {
- width += 2 * kTooltipBorderWidth;
- height += 2 * kTooltipBorderWidth;
+
+ if (!widget_) {
+ widget_ = CreateTooltipWidget(tooltip_window_);
+ widget_->SetContentsView(&label_);
+ widget_->AddObserver(this);
}
- CreateWidget();
+
SetTooltipBounds(location, width, height);
+
+ ui::NativeTheme* native_theme = widget_->GetNativeTheme();
+ label_.set_background(
+ views::Background::CreateSolidBackground(
+ native_theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TooltipBackground)));
+
+ label_.SetAutoColorReadabilityEnabled(false);
+ label_.SetEnabledColor(native_theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TooltipText));
}
void TooltipAura::Show() {
- if (widget_)
+ if (widget_) {
widget_->Show();
+ widget_->StackAtTop();
+ }
}
void TooltipAura::Hide() {