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

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

Issue 2556083002: Don't subtract border from max size for display rect. (Closed)
Patch Set: RenderTextTestApi Created 4 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
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/display.h" 12 #include "ui/display/display.h"
13 #include "ui/display/screen.h" 13 #include "ui/display/screen.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/render_text.h" 15 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/test/render_text_test_api.h"
16 #include "ui/gfx/text_elider.h" 17 #include "ui/gfx/text_elider.h"
17 #include "ui/gfx/text_utils.h" 18 #include "ui/gfx/text_utils.h"
18 #include "ui/native_theme/native_theme.h" 19 #include "ui/native_theme/native_theme.h"
19 #include "ui/views/background.h" 20 #include "ui/views/background.h"
20 #include "ui/views/border.h" 21 #include "ui/views/border.h"
21 #include "ui/views/painter.h" 22 #include "ui/views/painter.h"
22 #include "ui/views/view.h" 23 #include "ui/views/view.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 namespace { 26 namespace {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // opaque. 135 // opaque.
135 render_text_->set_subpixel_rendering_suppressed( 136 render_text_->set_subpixel_rendering_suppressed(
136 SkColorGetA(background_color) != 0xFF); 137 SkColorGetA(background_color) != 0xFF);
137 } 138 }
138 139
139 void SetMaxWidth(int width) { 140 void SetMaxWidth(int width) {
140 max_width_ = width; 141 max_width_ = width;
141 ResetDisplayRect(); 142 ResetDisplayRect();
142 } 143 }
143 144
145 size_t GetLineSizeForTest() {
146 return gfx::test::RenderTextTestApi(render_text_.get()).lines().size();
147 }
148
144 private: 149 private:
145 void ResetDisplayRect() { 150 void ResetDisplayRect() {
146 gfx::Insets insets = border()->GetInsets(); 151 render_text_->SetDisplayRect(gfx::Rect(0, 0, max_width_, 100000));
147 int max_text_width = max_width_ - insets.width();
148 render_text_->SetDisplayRect(gfx::Rect(0, 0, max_text_width, 100000));
149 } 152 }
150 153
151 std::unique_ptr<gfx::RenderText> render_text_; 154 std::unique_ptr<gfx::RenderText> render_text_;
152 int max_width_; 155 int max_width_;
153 156
154 DISALLOW_COPY_AND_ASSIGN(TooltipView); 157 DISALLOW_COPY_AND_ASSIGN(TooltipView);
155 }; 158 };
156 159
157 TooltipAura::TooltipAura() 160 TooltipAura::TooltipAura()
158 : tooltip_view_(new TooltipView), 161 : tooltip_view_(new TooltipView),
159 widget_(NULL), 162 widget_(NULL),
160 tooltip_window_(NULL) { 163 tooltip_window_(NULL) {
161 } 164 }
162 165
163 TooltipAura::~TooltipAura() { 166 TooltipAura::~TooltipAura() {
164 DestroyWidget(); 167 DestroyWidget();
165 } 168 }
166 169
170 size_t TooltipAura::GetLineSizeForTest() {
171 return tooltip_view_->GetLineSizeForTest();
172 }
173
167 void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos, 174 void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
168 const gfx::Size& tooltip_size) { 175 const gfx::Size& tooltip_size) {
169 gfx::Rect tooltip_rect(mouse_pos, tooltip_size); 176 gfx::Rect tooltip_rect(mouse_pos, tooltip_size);
170 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY); 177 tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
171 display::Screen* screen = display::Screen::GetScreen(); 178 display::Screen* screen = display::Screen::GetScreen();
172 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds()); 179 gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds());
173 180
174 // If tooltip is out of bounds on the x axis, we simply shift it 181 // If tooltip is out of bounds on the x axis, we simply shift it
175 // horizontally by the offset. 182 // horizontally by the offset.
176 if (tooltip_rect.right() > display_bounds.right()) { 183 if (tooltip_rect.right() > display_bounds.right()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 248 }
242 249
243 void TooltipAura::OnWidgetDestroying(views::Widget* widget) { 250 void TooltipAura::OnWidgetDestroying(views::Widget* widget) {
244 DCHECK_EQ(widget_, widget); 251 DCHECK_EQ(widget_, widget);
245 widget_ = NULL; 252 widget_ = NULL;
246 tooltip_window_ = NULL; 253 tooltip_window_ = NULL;
247 } 254 }
248 255
249 } // namespace corewm 256 } // namespace corewm
250 } // namespace views 257 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698