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

Side by Side Diff: ui/views/bubble/bubble_border.cc

Issue 1802073002: Makes vertical alignment of location bar bubbles same (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Makes vertical alignment of location bar bubbles same (updated tests) Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bubble/bubble_border.h" 5 #include "ui/views/bubble/bubble_border.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkPaint.h" 10 #include "third_party/skia/include/core/SkPaint.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 BubbleBorder::~BubbleBorder() {} 157 BubbleBorder::~BubbleBorder() {}
158 158
159 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect, 159 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect,
160 const gfx::Size& contents_size) const { 160 const gfx::Size& contents_size) const {
161 int x = anchor_rect.x(); 161 int x = anchor_rect.x();
162 int y = anchor_rect.y(); 162 int y = anchor_rect.y();
163 int w = anchor_rect.width(); 163 int w = anchor_rect.width();
164 int h = anchor_rect.height(); 164 int h = anchor_rect.height();
165 const gfx::Size size(GetSizeForContentsSize(contents_size)); 165 const gfx::Size size(GetSizeForContentsSize(contents_size));
166 const int arrow_offset = GetArrowOffset(size); 166 const int arrow_offset = GetArrowOffset(size);
167 const int arrow_size = 167 int arrow_shift =
168 images_->arrow_interior_thickness + kStroke - images_->arrow_thickness; 168 images_->arrow_interior_thickness + kStroke - images_->arrow_thickness;
169 // When arrow is painted transparently the visible border of the bubble needs
170 // to be positioned at the same bounds as when the arrow is shown. To achieve
171 // this shift the bounds by |arrow_interior_thickness|;
Peter Kasting 2016/03/17 06:16:15 Nit: ; -> . But maybe better, just remove the las
varkha 2016/03/18 01:21:13 Done.
172 if (arrow_paint_type_ == PAINT_TRANSPARENT)
173 arrow_shift += images_->arrow_interior_thickness;
169 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR; 174 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR;
170 175
171 // Calculate the bubble coordinates based on the border and arrow settings. 176 // Calculate the bubble coordinates based on the border and arrow settings.
172 if (is_arrow_on_horizontal(arrow_)) { 177 if (is_arrow_on_horizontal(arrow_)) {
173 if (is_arrow_on_left(arrow_)) { 178 if (is_arrow_on_left(arrow_)) {
174 x += mid_anchor ? w / 2 - arrow_offset : kStroke - GetBorderThickness(); 179 x += mid_anchor ? w / 2 - arrow_offset : kStroke - GetBorderThickness();
175 } else if (is_arrow_at_center(arrow_)) { 180 } else if (is_arrow_at_center(arrow_)) {
176 x += w / 2 - arrow_offset; 181 x += w / 2 - arrow_offset;
177 } else { 182 } else {
178 x += mid_anchor ? w / 2 + arrow_offset - size.width() : 183 x += mid_anchor ? w / 2 + arrow_offset - size.width() :
179 w - size.width() + GetBorderThickness() - kStroke; 184 w - size.width() + GetBorderThickness() - kStroke;
180 } 185 }
181 y += is_arrow_on_top(arrow_) ? h + arrow_size : -arrow_size - size.height(); 186 y += is_arrow_on_top(arrow_) ? h + arrow_shift
187 : -arrow_shift - size.height();
182 } else if (has_arrow(arrow_)) { 188 } else if (has_arrow(arrow_)) {
183 x += is_arrow_on_left(arrow_) ? w + arrow_size : -arrow_size - size.width(); 189 x += is_arrow_on_left(arrow_) ? w + arrow_shift
190 : -arrow_shift - size.width();
184 if (is_arrow_on_top(arrow_)) { 191 if (is_arrow_on_top(arrow_)) {
185 y += mid_anchor ? h / 2 - arrow_offset : kStroke - GetBorderThickness(); 192 y += mid_anchor ? h / 2 - arrow_offset : kStroke - GetBorderThickness();
186 } else if (is_arrow_at_center(arrow_)) { 193 } else if (is_arrow_at_center(arrow_)) {
187 y += h / 2 - arrow_offset; 194 y += h / 2 - arrow_offset;
188 } else { 195 } else {
189 y += mid_anchor ? h / 2 + arrow_offset - size.height() : 196 y += mid_anchor ? h / 2 + arrow_offset - size.height() :
190 h - size.height() + GetBorderThickness() - kStroke; 197 h - size.height() + GetBorderThickness() - kStroke;
191 } 198 }
192 } else { 199 } else {
193 x += (w - size.width()) / 2; 200 x += (w - size.width()) / 2;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 canvas->sk_canvas()->clipRect(arrow_rect, SkRegion::kDifference_Op); 253 canvas->sk_canvas()->clipRect(arrow_rect, SkRegion::kDifference_Op);
247 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); 254 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds);
248 canvas->Restore(); 255 canvas->Restore();
249 256
250 DrawArrow(canvas, arrow_bounds); 257 DrawArrow(canvas, arrow_bounds);
251 } 258 }
252 259
253 gfx::Insets BubbleBorder::GetInsets() const { 260 gfx::Insets BubbleBorder::GetInsets() const {
254 // The insets contain the stroke and shadow pixels outside the bubble fill. 261 // The insets contain the stroke and shadow pixels outside the bubble fill.
255 const int inset = GetBorderThickness(); 262 const int inset = GetBorderThickness();
256 if ((arrow_paint_type_ == PAINT_NONE) || !has_arrow(arrow_)) 263 if (arrow_paint_type_ == PAINT_NONE ||
264 arrow_paint_type_ == PAINT_TRANSPARENT || !has_arrow(arrow_)) {
Peter Kasting 2016/03/17 06:16:15 Nit: Simpler, avoids {}: if (arrow_paint_type_
varkha 2016/03/18 01:21:13 Done.
257 return gfx::Insets(inset); 265 return gfx::Insets(inset);
266 }
258 267
259 int first_inset = inset; 268 int first_inset = inset;
260 int second_inset = std::max(inset, images_->arrow_thickness); 269 int second_inset = std::max(inset, images_->arrow_thickness);
261 if (is_arrow_on_horizontal(arrow_) ? 270 if (is_arrow_on_horizontal(arrow_) ?
262 is_arrow_on_top(arrow_) : is_arrow_on_left(arrow_)) 271 is_arrow_on_top(arrow_) : is_arrow_on_left(arrow_))
263 std::swap(first_inset, second_inset); 272 std::swap(first_inset, second_inset);
264 return is_arrow_on_horizontal(arrow_) ? 273 return is_arrow_on_horizontal(arrow_) ?
265 gfx::Insets(first_inset, inset, second_inset, inset) : 274 gfx::Insets(first_inset, inset, second_inset, inset) :
266 gfx::Insets(inset, first_inset, inset, second_inset); 275 gfx::Insets(inset, first_inset, inset, second_inset);
267 } 276 }
268 277
269 gfx::Size BubbleBorder::GetMinimumSize() const { 278 gfx::Size BubbleBorder::GetMinimumSize() const {
270 return GetSizeForContentsSize(gfx::Size()); 279 return GetSizeForContentsSize(gfx::Size());
271 } 280 }
272 281
273 gfx::Size BubbleBorder::GetSizeForContentsSize( 282 gfx::Size BubbleBorder::GetSizeForContentsSize(
274 const gfx::Size& contents_size) const { 283 const gfx::Size& contents_size) const {
275 // Enlarge the contents size by the thickness of the border images. 284 // Enlarge the contents size by the thickness of the border images.
276 gfx::Size size(contents_size); 285 gfx::Size size(contents_size);
277 const gfx::Insets insets = GetInsets(); 286 const gfx::Insets insets = GetInsets();
278 size.Enlarge(insets.width(), insets.height()); 287 size.Enlarge(insets.width(), insets.height());
279 288
280 // Ensure the bubble is large enough to not overlap border and arrow images. 289 // Ensure the bubble is large enough to not overlap border and arrow images.
281 const int min = 2 * images_->border_thickness; 290 const int min = 2 * images_->border_thickness;
291 // Only take arrow image sizes into account when the bubble tip is shown.
292 if (arrow_paint_type_ == PAINT_NONE ||
293 arrow_paint_type_ == PAINT_TRANSPARENT || !has_arrow(arrow_)) {
294 size.SetToMax(gfx::Size(min, min));
295 return size;
296 }
282 const int min_with_arrow_width = min + images_->arrow_width; 297 const int min_with_arrow_width = min + images_->arrow_width;
283 const int min_with_arrow_thickness = images_->border_thickness + 298 const int min_with_arrow_thickness = images_->border_thickness +
284 std::max(images_->arrow_thickness + images_->border_interior_thickness, 299 std::max(images_->arrow_thickness + images_->border_interior_thickness,
285 images_->border_thickness); 300 images_->border_thickness);
286 // Only take arrow image sizes into account when the bubble tip is shown. 301 if (is_arrow_on_horizontal(arrow_))
287 if (arrow_paint_type_ == PAINT_NONE || !has_arrow(arrow_))
288 size.SetToMax(gfx::Size(min, min));
289 else if (is_arrow_on_horizontal(arrow_))
290 size.SetToMax(gfx::Size(min_with_arrow_width, min_with_arrow_thickness)); 302 size.SetToMax(gfx::Size(min_with_arrow_width, min_with_arrow_thickness));
291 else 303 else
292 size.SetToMax(gfx::Size(min_with_arrow_thickness, min_with_arrow_width)); 304 size.SetToMax(gfx::Size(min_with_arrow_thickness, min_with_arrow_width));
293 return size; 305 return size;
294 } 306 }
295 307
296 gfx::ImageSkia* BubbleBorder::GetArrowImage() const { 308 gfx::ImageSkia* BubbleBorder::GetArrowImage() const {
297 if (!has_arrow(arrow_)) 309 if (!has_arrow(arrow_))
298 return NULL; 310 return NULL;
299 if (is_arrow_on_horizontal(arrow_)) { 311 if (is_arrow_on_horizontal(arrow_)) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 paint.setStyle(SkPaint::kFill_Style); 406 paint.setStyle(SkPaint::kFill_Style);
395 paint.setColor(border_->background_color()); 407 paint.setColor(border_->background_color());
396 SkPath path; 408 SkPath path;
397 gfx::Rect bounds(view->GetLocalBounds()); 409 gfx::Rect bounds(view->GetLocalBounds());
398 bounds.Inset(border_->GetInsets()); 410 bounds.Inset(border_->GetInsets());
399 411
400 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); 412 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint);
401 } 413 }
402 414
403 } // namespace views 415 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698