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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/corewm/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/corewm/tooltip_aura.cc
diff --git a/ui/views/corewm/tooltip_aura.cc b/ui/views/corewm/tooltip_aura.cc
index e51a87265a5652fd7e9d62f24181d40264d0e436..f33eaca7d4084325afd9d1a70ebb42f21d475687 100644
--- a/ui/views/corewm/tooltip_aura.cc
+++ b/ui/views/corewm/tooltip_aura.cc
@@ -9,6 +9,7 @@
#include "base/strings/string_util.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
+#include "ui/base/material_design/material_design_controller.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
@@ -18,6 +19,7 @@
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
+#include "ui/views/painter.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
@@ -27,6 +29,9 @@ namespace {
// be wrapped.
const int kTooltipMaxWidthPixels = 400;
+// Corner radius of tooltip background used with Material Design.
+const float kTooltipCornerRadius = 2.f;
+
// FIXME: get cursor offset from actual cursor size.
const int kCursorOffsetX = 10;
const int kCursorOffsetY = 15;
@@ -42,6 +47,10 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) {
DCHECK(params.context);
params.keep_on_top = true;
params.accept_events = false;
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
+ params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_NONE;
+ }
widget->Init(params);
return widget;
}
@@ -57,11 +66,13 @@ class TooltipAura::TooltipView : public views::View {
TooltipView()
: render_text_(gfx::RenderText::CreateInstance()),
max_width_(0) {
- const int kHorizontalPadding = 3;
- const int kVerticalPadding = 2;
- SetBorder(Border::CreateEmptyBorder(
- kVerticalPadding, kHorizontalPadding,
- kVerticalPadding, kHorizontalPadding));
+ const bool material = ui::MaterialDesignController::IsModeMaterial();
+ const int kHorizontalPadding = material ? 8 : 3;
+ const int kVerticalPaddingTop = material ? 4 : 2;
+ const int kVerticalPaddingBottom = material ? 5 : kVerticalPaddingTop;
+ SetBorder(Border::CreateEmptyBorder(kVerticalPaddingTop, kHorizontalPadding,
+ kVerticalPaddingBottom,
+ kHorizontalPadding));
set_owned_by_client();
render_text_->SetWordWrapBehavior(gfx::WRAP_LONG_WORDS);
@@ -107,6 +118,20 @@ class TooltipAura::TooltipView : public views::View {
render_text_->SetColor(color);
}
+ void SetBackgroundColor(SkColor background_color) {
+ views::Background* background =
+ ui::MaterialDesignController::IsModeMaterial()
+ ? views::Background::CreateBackgroundPainter(
+ true, views::Painter::CreateSolidRoundRectPainter(
+ background_color, kTooltipCornerRadius))
+ : views::Background::CreateSolidBackground(background_color);
+ set_background(background);
+ // Force the text color to be readable when |background_color| is not
+ // opaque.
+ render_text_->set_subpixel_rendering_suppressed(
+ SkColorGetA(background_color) != 0xFF);
+ }
+
void SetMaxWidth(int width) {
max_width_ = width;
ResetDisplayRect();
@@ -188,10 +213,8 @@ void TooltipAura::SetText(aura::Window* window,
SetTooltipBounds(location, tooltip_view_->GetPreferredSize());
ui::NativeTheme* native_theme = widget_->GetNativeTheme();
- tooltip_view_->set_background(
- views::Background::CreateSolidBackground(
- native_theme->GetSystemColor(
- ui::NativeTheme::kColorId_TooltipBackground)));
+ tooltip_view_->SetBackgroundColor(native_theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TooltipBackground));
tooltip_view_->SetForegroundColor(native_theme->GetSystemColor(
ui::NativeTheme::kColorId_TooltipText));
}
« 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