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

Side by Side Diff: ui/aura_shell/shell_tooltip_manager.cc

Issue 8821028: aura: Draw shadows around tooltip windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: increase horizontal padding Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura_shell/image_grid_unittest.cc ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/aura_shell/shell_tooltip_manager.h" 5 #include "ui/aura_shell/shell_tooltip_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h"
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/string_split.h" 11 #include "base/string_split.h"
11 #include "base/time.h" 12 #include "base/time.h"
13 #include "ui/aura/aura_switches.h"
12 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/event.h" 15 #include "ui/aura/event.h"
14 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
15 #include "ui/aura_shell/shell.h" 17 #include "ui/aura_shell/shell.h"
16 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/base/text/text_elider.h" 19 #include "ui/base/text/text_elider.h"
18 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
19 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
20 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
21 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
22 #include "ui/views/background.h" 24 #include "ui/views/background.h"
23 #include "ui/views/border.h" 25 #include "ui/views/border.h"
24 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
25 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
26 28
27 namespace { 29 namespace {
28 30
29 SkColor kTooltipBackground = 0xFFFFFFCC; 31 const SkColor kTooltipBackground = 0xFFFFFFCC;
30 SkColor kTooltipBorder = 0xFF000000; 32 const SkColor kTooltipBorder = 0xFF646450;
31 int kTooltipBorderWidth = 1; 33 const int kTooltipBorderWidth = 1;
32 int kTooltipTimeoutMs = 500; 34 const int kTooltipHorizontalPadding = 3;
35 // TODO(derat): This padding is needed on Chrome OS devices but seems excessive
36 // when running the same binary on a Linux workstation; presumably there's a
37 // difference in font metrics. Rationalize this.
38 const int kTooltipVerticalPadding = 2;
39 const int kTooltipTimeoutMs = 500;
33 40
34 // FIXME: get cursor offset from actual cursor size. 41 // FIXME: get cursor offset from actual cursor size.
35 int kCursorOffsetX = 10; 42 const int kCursorOffsetX = 10;
36 int kCursorOffsetY = 15; 43 const int kCursorOffsetY = 15;
37 44
38 // Maximum number of characters we allow in a tooltip. 45 // Maximum number of characters we allow in a tooltip.
39 const size_t kMaxTooltipLength = 1024; 46 const size_t kMaxTooltipLength = 1024;
40 47
41 // Maximum number of lines we allow in the tooltip. 48 // Maximum number of lines we allow in the tooltip.
42 const size_t kMaxLines = 6; 49 const size_t kMaxLines = 6;
43 50
44 // Trims the tooltip to fit, setting |text| to the clipped result, 51 // Trims the tooltip to fit, setting |text| to the clipped result,
45 // |max_width| to the width (in pixels) of the clipped text and |line_count| 52 // |max_width| to the width (in pixels) of the clipped text and |line_count|
46 // to the number of lines of text in the tooltip. |x| and |y| give the 53 // to the number of lines of text in the tooltip. |x| and |y| give the
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } // namespace 107 } // namespace
101 108
102 namespace aura_shell { 109 namespace aura_shell {
103 110
104 // Displays a widget with tooltip using a views::Label. 111 // Displays a widget with tooltip using a views::Label.
105 class ShellTooltipManager::Tooltip { 112 class ShellTooltipManager::Tooltip {
106 public: 113 public:
107 Tooltip() { 114 Tooltip() {
108 label_.set_background( 115 label_.set_background(
109 views::Background::CreateSolidBackground(kTooltipBackground)); 116 views::Background::CreateSolidBackground(kTooltipBackground));
110 label_.set_border( 117 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraNoShadows)) {
111 views::Border::CreateSolidBorder(kTooltipBorderWidth, kTooltipBorder)); 118 label_.set_border(
119 views::Border::CreateSolidBorder(kTooltipBorderWidth,
120 kTooltipBorder));
121 }
112 label_.set_parent_owned(false); 122 label_.set_parent_owned(false);
113 widget_.reset(CreateTooltip()); 123 widget_.reset(CreateTooltip());
114 widget_->SetContentsView(&label_); 124 widget_->SetContentsView(&label_);
115 widget_->Activate(); 125 widget_->Activate();
116 } 126 }
117 127
118 ~Tooltip() { 128 ~Tooltip() {
119 widget_->Close(); 129 widget_->Close();
120 } 130 }
121 131
122 // Updates the text on the tooltip and resizes to fit. 132 // Updates the text on the tooltip and resizes to fit.
123 void SetText(string16 tooltip_text, gfx::Point location) { 133 void SetText(string16 tooltip_text, gfx::Point location) {
124 int max_width, line_count; 134 int max_width, line_count;
125 TrimTooltipToFit(&tooltip_text, &max_width, &line_count, 135 TrimTooltipToFit(&tooltip_text, &max_width, &line_count,
126 location.x(), location.y()); 136 location.x(), location.y());
127 label_.SetText(tooltip_text); 137 label_.SetText(tooltip_text);
128 138
129 SetTooltipBounds(location, max_width + 2 * kTooltipBorderWidth, 139 int width = max_width + 2 * kTooltipHorizontalPadding;
130 label_.GetPreferredSize().height()); 140 int height = label_.GetPreferredSize().height() +
141 2 * kTooltipVerticalPadding;
142 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraNoShadows)) {
143 width += 2 * kTooltipBorderWidth;
144 height += 2 * kTooltipBorderWidth;
145 }
146 SetTooltipBounds(location, width, height);
131 } 147 }
132 148
133 // Shows the tooltip. 149 // Shows the tooltip.
134 void Show() { 150 void Show() {
135 widget_->Show(); 151 widget_->Show();
136 } 152 }
137 153
138 // Hides the tooltip. 154 // Hides the tooltip.
139 void Hide() { 155 void Hide() {
140 widget_->Hide(); 156 widget_->Hide();
(...skipping 19 matching lines...) Expand all
160 gfx::Rect monitor_bounds = 176 gfx::Rect monitor_bounds =
161 gfx::Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin()); 177 gfx::Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin());
162 widget_->SetBounds(tooltip_rect.AdjustToFit(monitor_bounds)); 178 widget_->SetBounds(tooltip_rect.AdjustToFit(monitor_bounds));
163 } 179 }
164 180
165 }; 181 };
166 182
167 //////////////////////////////////////////////////////////////////////////////// 183 ////////////////////////////////////////////////////////////////////////////////
168 // ShellTooltipManager public: 184 // ShellTooltipManager public:
169 185
170 ShellTooltipManager::ShellTooltipManager() : aura::EventFilter(NULL), 186 ShellTooltipManager::ShellTooltipManager()
171 tooltip_window_(NULL), 187 : aura::EventFilter(NULL),
172 tooltip_(new Tooltip) { 188 tooltip_window_(NULL),
189 tooltip_(new Tooltip) {
173 tooltip_timer_.Start(FROM_HERE, 190 tooltip_timer_.Start(FROM_HERE,
174 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), 191 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
175 this, &ShellTooltipManager::TooltipTimerFired); 192 this, &ShellTooltipManager::TooltipTimerFired);
176 } 193 }
177 194
178 ShellTooltipManager::~ShellTooltipManager() { 195 ShellTooltipManager::~ShellTooltipManager() {
179 if (tooltip_window_) 196 if (tooltip_window_)
180 tooltip_window_->RemoveObserver(this); 197 tooltip_window_->RemoveObserver(this);
181 } 198 }
182 199
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 289 }
273 290
274 // static 291 // static
275 int TooltipClient::GetMaxWidth(int x, int y) { 292 int TooltipClient::GetMaxWidth(int x, int y) {
276 gfx::Rect monitor_bounds = 293 gfx::Rect monitor_bounds =
277 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y)); 294 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
278 return (monitor_bounds.width() + 1) / 2; 295 return (monitor_bounds.width() + 1) / 2;
279 } 296 }
280 297
281 } // namespace aura 298 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura_shell/image_grid_unittest.cc ('k') | ui/views/widget/native_widget_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698