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

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 (nits and test simplification) 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;
Evan Stade 2016/03/18 01:49:21 took me a good while to figure out what this is. I
varkha 2016/03/18 04:14:41 The image we use for the arrow (I am taking the ar
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.
171 if (arrow_paint_type_ == PAINT_TRANSPARENT)
172 arrow_shift += images_->arrow_interior_thickness;
msw 2016/03/18 02:02:52 Hmm, I don't understand why adding the interior th
varkha 2016/03/18 04:14:41 No. I am not logically adding it again (although t
169 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR; 173 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR;
170 174
171 // Calculate the bubble coordinates based on the border and arrow settings. 175 // Calculate the bubble coordinates based on the border and arrow settings.
172 if (is_arrow_on_horizontal(arrow_)) { 176 if (is_arrow_on_horizontal(arrow_)) {
173 if (is_arrow_on_left(arrow_)) { 177 if (is_arrow_on_left(arrow_)) {
174 x += mid_anchor ? w / 2 - arrow_offset : kStroke - GetBorderThickness(); 178 x += mid_anchor ? w / 2 - arrow_offset : kStroke - GetBorderThickness();
175 } else if (is_arrow_at_center(arrow_)) { 179 } else if (is_arrow_at_center(arrow_)) {
176 x += w / 2 - arrow_offset; 180 x += w / 2 - arrow_offset;
177 } else { 181 } else {
178 x += mid_anchor ? w / 2 + arrow_offset - size.width() : 182 x += mid_anchor ? w / 2 + arrow_offset - size.width() :
179 w - size.width() + GetBorderThickness() - kStroke; 183 w - size.width() + GetBorderThickness() - kStroke;
180 } 184 }
181 y += is_arrow_on_top(arrow_) ? h + arrow_size : -arrow_size - size.height(); 185 y += is_arrow_on_top(arrow_) ? h + arrow_shift
186 : -arrow_shift - size.height();
182 } else if (has_arrow(arrow_)) { 187 } else if (has_arrow(arrow_)) {
183 x += is_arrow_on_left(arrow_) ? w + arrow_size : -arrow_size - size.width(); 188 x += is_arrow_on_left(arrow_) ? w + arrow_shift
189 : -arrow_shift - size.width();
184 if (is_arrow_on_top(arrow_)) { 190 if (is_arrow_on_top(arrow_)) {
185 y += mid_anchor ? h / 2 - arrow_offset : kStroke - GetBorderThickness(); 191 y += mid_anchor ? h / 2 - arrow_offset : kStroke - GetBorderThickness();
186 } else if (is_arrow_at_center(arrow_)) { 192 } else if (is_arrow_at_center(arrow_)) {
187 y += h / 2 - arrow_offset; 193 y += h / 2 - arrow_offset;
188 } else { 194 } else {
189 y += mid_anchor ? h / 2 + arrow_offset - size.height() : 195 y += mid_anchor ? h / 2 + arrow_offset - size.height() :
190 h - size.height() + GetBorderThickness() - kStroke; 196 h - size.height() + GetBorderThickness() - kStroke;
191 } 197 }
192 } else { 198 } else {
193 x += (w - size.width()) / 2; 199 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); 252 canvas->sk_canvas()->clipRect(arrow_rect, SkRegion::kDifference_Op);
247 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); 253 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds);
248 canvas->Restore(); 254 canvas->Restore();
249 255
250 DrawArrow(canvas, arrow_bounds); 256 DrawArrow(canvas, arrow_bounds);
251 } 257 }
252 258
253 gfx::Insets BubbleBorder::GetInsets() const { 259 gfx::Insets BubbleBorder::GetInsets() const {
254 // The insets contain the stroke and shadow pixels outside the bubble fill. 260 // The insets contain the stroke and shadow pixels outside the bubble fill.
255 const int inset = GetBorderThickness(); 261 const int inset = GetBorderThickness();
256 if ((arrow_paint_type_ == PAINT_NONE) || !has_arrow(arrow_)) 262 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_))
257 return gfx::Insets(inset); 263 return gfx::Insets(inset);
258 264
259 int first_inset = inset; 265 int first_inset = inset;
260 int second_inset = std::max(inset, images_->arrow_thickness); 266 int second_inset = std::max(inset, images_->arrow_thickness);
261 if (is_arrow_on_horizontal(arrow_) ? 267 if (is_arrow_on_horizontal(arrow_) ?
262 is_arrow_on_top(arrow_) : is_arrow_on_left(arrow_)) 268 is_arrow_on_top(arrow_) : is_arrow_on_left(arrow_))
263 std::swap(first_inset, second_inset); 269 std::swap(first_inset, second_inset);
264 return is_arrow_on_horizontal(arrow_) ? 270 return is_arrow_on_horizontal(arrow_) ?
265 gfx::Insets(first_inset, inset, second_inset, inset) : 271 gfx::Insets(first_inset, inset, second_inset, inset) :
266 gfx::Insets(inset, first_inset, inset, second_inset); 272 gfx::Insets(inset, first_inset, inset, second_inset);
267 } 273 }
268 274
269 gfx::Size BubbleBorder::GetMinimumSize() const { 275 gfx::Size BubbleBorder::GetMinimumSize() const {
270 return GetSizeForContentsSize(gfx::Size()); 276 return GetSizeForContentsSize(gfx::Size());
271 } 277 }
272 278
273 gfx::Size BubbleBorder::GetSizeForContentsSize( 279 gfx::Size BubbleBorder::GetSizeForContentsSize(
274 const gfx::Size& contents_size) const { 280 const gfx::Size& contents_size) const {
275 // Enlarge the contents size by the thickness of the border images. 281 // Enlarge the contents size by the thickness of the border images.
276 gfx::Size size(contents_size); 282 gfx::Size size(contents_size);
277 const gfx::Insets insets = GetInsets(); 283 const gfx::Insets insets = GetInsets();
278 size.Enlarge(insets.width(), insets.height()); 284 size.Enlarge(insets.width(), insets.height());
279 285
280 // Ensure the bubble is large enough to not overlap border and arrow images. 286 // Ensure the bubble is large enough to not overlap border and arrow images.
281 const int min = 2 * images_->border_thickness; 287 const int min = 2 * images_->border_thickness;
288 // Only take arrow image sizes into account when the bubble tip is shown.
289 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) {
290 size.SetToMax(gfx::Size(min, min));
291 return size;
292 }
282 const int min_with_arrow_width = min + images_->arrow_width; 293 const int min_with_arrow_width = min + images_->arrow_width;
283 const int min_with_arrow_thickness = images_->border_thickness + 294 const int min_with_arrow_thickness = images_->border_thickness +
284 std::max(images_->arrow_thickness + images_->border_interior_thickness, 295 std::max(images_->arrow_thickness + images_->border_interior_thickness,
285 images_->border_thickness); 296 images_->border_thickness);
286 // Only take arrow image sizes into account when the bubble tip is shown. 297 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)); 298 size.SetToMax(gfx::Size(min_with_arrow_width, min_with_arrow_thickness));
291 else 299 else
292 size.SetToMax(gfx::Size(min_with_arrow_thickness, min_with_arrow_width)); 300 size.SetToMax(gfx::Size(min_with_arrow_thickness, min_with_arrow_width));
293 return size; 301 return size;
294 } 302 }
295 303
296 gfx::ImageSkia* BubbleBorder::GetArrowImage() const { 304 gfx::ImageSkia* BubbleBorder::GetArrowImage() const {
297 if (!has_arrow(arrow_)) 305 if (!has_arrow(arrow_))
298 return NULL; 306 return NULL;
299 if (is_arrow_on_horizontal(arrow_)) { 307 if (is_arrow_on_horizontal(arrow_)) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 paint.setStyle(SkPaint::kFill_Style); 402 paint.setStyle(SkPaint::kFill_Style);
395 paint.setColor(border_->background_color()); 403 paint.setColor(border_->background_color());
396 SkPath path; 404 SkPath path;
397 gfx::Rect bounds(view->GetLocalBounds()); 405 gfx::Rect bounds(view->GetLocalBounds());
398 bounds.Inset(border_->GetInsets()); 406 bounds.Inset(border_->GetInsets());
399 407
400 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); 408 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint);
401 } 409 }
402 410
403 } // namespace views 411 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc ('k') | ui/views/bubble/bubble_border_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698