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

Side by Side Diff: ui/views/corewm/tooltip_aura.cc

Issue 1915363002: Rename gfx::Display/Screen to display::Display/Screen in views/wm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanups Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/corewm/tooltip_controller.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 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"
11 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
12 #include "ui/display/screen.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/render_text.h" 14 #include "ui/gfx/render_text.h"
14 #include "ui/gfx/screen.h"
15 #include "ui/gfx/text_elider.h" 15 #include "ui/gfx/text_elider.h"
16 #include "ui/gfx/text_utils.h" 16 #include "ui/gfx/text_utils.h"
17 #include "ui/native_theme/native_theme.h" 17 #include "ui/native_theme/native_theme.h"
18 #include "ui/views/background.h" 18 #include "ui/views/background.h"
19 #include "ui/views/border.h" 19 #include "ui/views/border.h"
20 #include "ui/views/view.h" 20 #include "ui/views/view.h"
21 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 22
23 namespace { 23 namespace {
24 24
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 132
133 TooltipAura::~TooltipAura() { 133 TooltipAura::~TooltipAura() {
134 DestroyWidget(); 134 DestroyWidget();
135 } 135 }
136 136
137 void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos, 137 void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
138 const gfx::Size& tooltip_size) { 138 const gfx::Size& tooltip_size) {
139 gfx::Rect tooltip_rect(mouse_pos, tooltip_size); 139 gfx::Rect tooltip_rect(mouse_pos, tooltip_size);
140 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); 140 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
141 gfx::Screen* screen = gfx::Screen::GetScreen(); 141 display::Screen* screen = display::Screen::GetScreen();
142 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds()); 142 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds());
143 143
144 // If tooltip is out of bounds on the x axis, we simply shift it 144 // If tooltip is out of bounds on the x axis, we simply shift it
145 // horizontally by the offset. 145 // horizontally by the offset.
146 if (tooltip_rect.right() > display_bounds.right()) { 146 if (tooltip_rect.right() > display_bounds.right()) {
147 int h_offset = tooltip_rect.right() - display_bounds.right(); 147 int h_offset = tooltip_rect.right() - display_bounds.right();
148 tooltip_rect.Offset(-h_offset, 0); 148 tooltip_rect.Offset(-h_offset, 0);
149 } 149 }
150 150
151 // If tooltip is out of bounds on the y axis, we flip it to appear above the 151 // If tooltip is out of bounds on the y axis, we flip it to appear above the
152 // mouse cursor instead of below. 152 // mouse cursor instead of below.
153 if (tooltip_rect.bottom() > display_bounds.bottom()) 153 if (tooltip_rect.bottom() > display_bounds.bottom())
154 tooltip_rect.set_y(mouse_pos.y() - tooltip_size.height()); 154 tooltip_rect.set_y(mouse_pos.y() - tooltip_size.height());
155 155
156 tooltip_rect.AdjustToFit(display_bounds); 156 tooltip_rect.AdjustToFit(display_bounds);
157 widget_->SetBounds(tooltip_rect); 157 widget_->SetBounds(tooltip_rect);
158 } 158 }
159 159
160 void TooltipAura::DestroyWidget() { 160 void TooltipAura::DestroyWidget() {
161 if (widget_) { 161 if (widget_) {
162 widget_->RemoveObserver(this); 162 widget_->RemoveObserver(this);
163 widget_->Close(); 163 widget_->Close();
164 widget_ = NULL; 164 widget_ = NULL;
165 } 165 }
166 } 166 }
167 167
168 int TooltipAura::GetMaxWidth(const gfx::Point& location) const { 168 int TooltipAura::GetMaxWidth(const gfx::Point& location) const {
169 gfx::Screen* screen = gfx::Screen::GetScreen(); 169 display::Screen* screen = display::Screen::GetScreen();
170 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds()); 170 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds());
171 return std::min(kTooltipMaxWidthPixels, (display_bounds.width() + 1) / 2); 171 return std::min(kTooltipMaxWidthPixels, (display_bounds.width() + 1) / 2);
172 } 172 }
173 173
174 void TooltipAura::SetText(aura::Window* window, 174 void TooltipAura::SetText(aura::Window* window,
175 const base::string16& tooltip_text, 175 const base::string16& tooltip_text,
176 const gfx::Point& location) { 176 const gfx::Point& location) {
177 tooltip_window_ = window; 177 tooltip_window_ = window;
178 tooltip_view_->SetMaxWidth(GetMaxWidth(location)); 178 tooltip_view_->SetMaxWidth(GetMaxWidth(location));
179 tooltip_view_->SetText(tooltip_text); 179 tooltip_view_->SetText(tooltip_text);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 213 }
214 214
215 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { 215 void TooltipAura::OnWidgetDestroying(views::Widget* widget) {
216 DCHECK_EQ(widget_, widget); 216 DCHECK_EQ(widget_, widget);
217 widget_ = NULL; 217 widget_ = NULL;
218 tooltip_window_ = NULL; 218 tooltip_window_ = NULL;
219 } 219 }
220 220
221 } // namespace corewm 221 } // namespace corewm
222 } // namespace views 222 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/corewm/tooltip_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698