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

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

Issue 2555373004: Apply new MD shadows to CrOS tray bubbles. (Closed)
Patch Set: leave activation alone 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 (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/SkDrawLooper.h" 10 #include "third_party/skia/include/core/SkDrawLooper.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 contents_bounds += gfx::Vector2d(-arrow_offset_, 0); 248 contents_bounds += gfx::Vector2d(-arrow_offset_, 0);
249 return contents_bounds; 249 return contents_bounds;
250 } 250 }
251 251
252 int x = anchor_rect.x(); 252 int x = anchor_rect.x();
253 int y = anchor_rect.y(); 253 int y = anchor_rect.y();
254 int w = anchor_rect.width(); 254 int w = anchor_rect.width();
255 int h = anchor_rect.height(); 255 int h = anchor_rect.height();
256 const gfx::Size size(GetSizeForContentsSize(contents_size)); 256 const gfx::Size size(GetSizeForContentsSize(contents_size));
257 const int arrow_offset = GetArrowOffset(size); 257 const int arrow_offset = GetArrowOffset(size);
258 const int stroke_width = shadow_ == NO_ASSETS ? 0 : kStroke;
James Cook 2016/12/09 19:40:13 nit: Can you add a comment in the enum saying what
Evan Stade 2016/12/09 23:06:16 Done.
258 // |arrow_shift| is necessary to visually align the tip of the bubble arrow 259 // |arrow_shift| is necessary to visually align the tip of the bubble arrow
259 // with the anchor point. This shift is an inverse of the shadow thickness. 260 // with the anchor point. This shift is an inverse of the shadow thickness.
260 int arrow_shift = UseMd() ? 0 : 261 int arrow_shift = UseMd() ? 0
261 images_->arrow_interior_thickness + kStroke - images_->arrow_thickness; 262 : images_->arrow_interior_thickness + stroke_width -
263 images_->arrow_thickness;
262 // When arrow is painted transparently the visible border of the bubble needs 264 // When arrow is painted transparently the visible border of the bubble needs
263 // to be positioned at the same bounds as when the arrow is shown. 265 // to be positioned at the same bounds as when the arrow is shown.
264 if (arrow_paint_type_ == PAINT_TRANSPARENT) 266 if (arrow_paint_type_ == PAINT_TRANSPARENT)
265 arrow_shift += images_->arrow_interior_thickness; 267 arrow_shift += images_->arrow_interior_thickness;
266 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR; 268 const bool mid_anchor = alignment_ == ALIGN_ARROW_TO_MID_ANCHOR;
267 269
268 // Calculate the bubble coordinates based on the border and arrow settings. 270 // Calculate the bubble coordinates based on the border and arrow settings.
269 if (is_arrow_on_horizontal(arrow_)) { 271 if (is_arrow_on_horizontal(arrow_)) {
270 if (is_arrow_on_left(arrow_)) { 272 if (is_arrow_on_left(arrow_)) {
271 x += mid_anchor ? w / 2 - arrow_offset : kStroke - GetBorderThickness(); 273 x += mid_anchor ? w / 2 - arrow_offset
274 : stroke_width - GetBorderThickness();
272 } else if (is_arrow_at_center(arrow_)) { 275 } else if (is_arrow_at_center(arrow_)) {
273 x += w / 2 - arrow_offset; 276 x += w / 2 - arrow_offset;
274 } else { 277 } else {
275 x += mid_anchor ? w / 2 + arrow_offset - size.width() : 278 x += mid_anchor ? w / 2 + arrow_offset - size.width()
276 w - size.width() + GetBorderThickness() - kStroke; 279 : w - size.width() + GetBorderThickness() - stroke_width;
277 } 280 }
278 y += is_arrow_on_top(arrow_) ? h + arrow_shift 281 y += is_arrow_on_top(arrow_) ? h + arrow_shift
279 : -arrow_shift - size.height(); 282 : -arrow_shift - size.height();
280 } else if (has_arrow(arrow_)) { 283 } else if (has_arrow(arrow_)) {
281 x += is_arrow_on_left(arrow_) ? w + arrow_shift 284 x += is_arrow_on_left(arrow_) ? w + arrow_shift
282 : -arrow_shift - size.width(); 285 : -arrow_shift - size.width();
283 if (is_arrow_on_top(arrow_)) { 286 if (is_arrow_on_top(arrow_)) {
284 y += mid_anchor ? h / 2 - arrow_offset : kStroke - GetBorderThickness(); 287 y += mid_anchor ? h / 2 - arrow_offset
288 : stroke_width - GetBorderThickness();
285 } else if (is_arrow_at_center(arrow_)) { 289 } else if (is_arrow_at_center(arrow_)) {
286 y += h / 2 - arrow_offset; 290 y += h / 2 - arrow_offset;
287 } else { 291 } else {
288 y += mid_anchor ? h / 2 + arrow_offset - size.height() : 292 y += mid_anchor ? h / 2 + arrow_offset - size.height()
289 h - size.height() + GetBorderThickness() - kStroke; 293 : h - size.height() + GetBorderThickness() - stroke_width;
290 } 294 }
291 } else { 295 } else {
292 x += (w - size.width()) / 2; 296 x += (w - size.width()) / 2;
293 y += (arrow_ == NONE) ? h : (h - size.height()) / 2; 297 y += (arrow_ == NONE) ? h : (h - size.height()) / 2;
294 } 298 }
295 299
296 return gfx::Rect(x, y, size.width(), size.height()); 300 return gfx::Rect(x, y, size.width(), size.height());
297 } 301 }
298 302
299 int BubbleBorder::GetBorderThickness() const { 303 int BubbleBorder::GetBorderThickness() const {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 paint.setStyle(SkPaint::kFill_Style); 573 paint.setStyle(SkPaint::kFill_Style);
570 paint.setColor(border_->background_color()); 574 paint.setColor(border_->background_color());
571 SkPath path; 575 SkPath path;
572 gfx::RectF bounds(view->GetLocalBounds()); 576 gfx::RectF bounds(view->GetLocalBounds());
573 bounds.Inset(gfx::InsetsF(border_->GetInsets())); 577 bounds.Inset(gfx::InsetsF(border_->GetInsets()));
574 578
575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); 579 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint);
576 } 580 }
577 581
578 } // namespace views 582 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698