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

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

Issue 2519313002: MacViews: For "NO_ASSET" MD bubbles, just use the border drawn by the window server. (Closed)
Patch Set: fix insets too Created 4 years, 1 month 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/bubble/bubble_border.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 canvas->Save(); 356 canvas->Save();
357 canvas->ClipRect(arrow_bounds, SkRegion::kDifference_Op); 357 canvas->ClipRect(arrow_bounds, SkRegion::kDifference_Op);
358 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); 358 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds);
359 canvas->Restore(); 359 canvas->Restore();
360 360
361 DrawArrow(canvas, arrow_bounds); 361 DrawArrow(canvas, arrow_bounds);
362 } 362 }
363 363
364 gfx::Insets BubbleBorder::GetInsets() const { 364 gfx::Insets BubbleBorder::GetInsets() const {
365 if (UseMd()) { 365 if (UseMd()) {
366 gfx::Insets blur(kLargeShadowBlur); 366 if (shadow_ == NO_ASSETS)
367 gfx::Insets offset(-kLargeShadowVerticalOffset, 0, 367 return gfx::Insets();
368 kLargeShadowVerticalOffset, 0); 368
369 gfx::Insets border(kBorderThicknessDip); 369 gfx::Insets blur(kLargeShadowBlur);
370 return blur + offset; 370 gfx::Insets offset(-kLargeShadowVerticalOffset, 0,
371 kLargeShadowVerticalOffset, 0);
372 gfx::Insets border(kBorderThicknessDip);
373 return blur + offset;
371 } 374 }
372 375
373 // The insets contain the stroke and shadow pixels outside the bubble fill. 376 // The insets contain the stroke and shadow pixels outside the bubble fill.
374 const int inset = GetBorderThickness(); 377 const int inset = GetBorderThickness();
375 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) 378 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_))
376 return gfx::Insets(inset); 379 return gfx::Insets(inset);
377 380
378 int first_inset = inset; 381 int first_inset = inset;
379 int second_inset = std::max(inset, images_->arrow_thickness); 382 int second_inset = std::max(inset, images_->arrow_thickness);
380 if (is_arrow_on_horizontal(arrow_) ? 383 if (is_arrow_on_horizontal(arrow_) ?
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y()); 501 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y());
499 SkPath path; 502 SkPath path;
500 GetArrowPathFromArrowBounds(arrow_bounds, &path); 503 GetArrowPathFromArrowBounds(arrow_bounds, &path);
501 SkPaint paint; 504 SkPaint paint;
502 paint.setStyle(SkPaint::kFill_Style); 505 paint.setStyle(SkPaint::kFill_Style);
503 paint.setColor(background_color_); 506 paint.setColor(background_color_);
504 507
505 canvas->DrawPath(path, paint); 508 canvas->DrawPath(path, paint);
506 } 509 }
507 510
511 SkRRect BubbleBorder::GetClientRect(const View& view) const {
512 // Clip out a round rect so the fill and shadow don't draw over the contents
msw 2016/11/22 18:27:22 nit: leave this comment in PaintMd (and PaintNoAss
tapted 2016/11/22 23:38:09 Done. Updated the header comment for GetClientRect
513 // of the bubble.
514 gfx::RectF bounds(view.GetLocalBounds());
515 bounds.Inset(GetInsets());
516 return SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds),
517 GetBorderCornerRadius(), GetBorderCornerRadius());
518 }
519
508 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) { 520 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) {
521 if (shadow_ == NO_ASSETS)
522 return PaintNoAssets(view, canvas);
523
509 gfx::ScopedCanvas scoped(canvas); 524 gfx::ScopedCanvas scoped(canvas);
510 525
511 SkPaint paint; 526 SkPaint paint;
512 std::vector<gfx::ShadowValue> shadows; 527 std::vector<gfx::ShadowValue> shadows;
513 // gfx::ShadowValue counts blur pixels both inside and outside the shape, 528 // gfx::ShadowValue counts blur pixels both inside and outside the shape,
514 // whereas these blur values only describe the outside portion, hence they 529 // whereas these blur values only describe the outside portion, hence they
515 // must be doubled. 530 // must be doubled.
516 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), 531 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset),
517 2 * kSmallShadowBlur, kSmallShadowColor); 532 2 * kSmallShadowBlur, kSmallShadowColor);
518 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), 533 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset),
519 2 * kLargeShadowBlur, kLargeShadowColor); 534 2 * kLargeShadowBlur, kLargeShadowColor);
520 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); 535 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows));
521 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); 536 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26));
522 paint.setAntiAlias(true); 537 paint.setAntiAlias(true);
523 538
524 gfx::RectF bounds(view.GetLocalBounds()); 539 SkRRect clip_r_rect = GetClientRect(view);
msw 2016/11/22 18:27:22 optional nit: rename |r_rect| and nix the copy bel
tapted 2016/11/22 23:38:09 Done.
525 bounds.Inset(GetInsets());
526 // Clip out a round rect so the fill and shadow don't draw over the contents
527 // of the bubble.
528 SkRRect clip_r_rect =
529 SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds), GetBorderCornerRadius(),
530 GetBorderCornerRadius());
531 canvas->sk_canvas()->clipRRect(clip_r_rect, SkRegion::kDifference_Op, 540 canvas->sk_canvas()->clipRRect(clip_r_rect, SkRegion::kDifference_Op,
532 true /*doAntiAlias*/); 541 true /*doAntiAlias*/);
533 542
534 // The border is drawn outside the content area. 543 // The border is drawn outside the content area.
535 SkRRect r_rect = clip_r_rect; 544 SkRRect r_rect = clip_r_rect;
536 const SkScalar one_pixel = 545 const SkScalar one_pixel =
537 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); 546 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale());
538 r_rect.inset(-one_pixel, -one_pixel); 547 r_rect.inset(-one_pixel, -one_pixel);
539 canvas->sk_canvas()->drawRRect(r_rect, paint); 548 canvas->sk_canvas()->drawRRect(r_rect, paint);
540 } 549 }
541 550
551 void BubbleBorder::PaintNoAssets(const View& view, gfx::Canvas* canvas) {
552 gfx::ScopedCanvas scoped(canvas);
553 canvas->sk_canvas()->clipRRect(GetClientRect(view), SkRegion::kDifference_Op,
554 true /*doAntiAlias*/);
555 canvas->sk_canvas()->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc);
556 }
557
542 internal::BorderImages* BubbleBorder::GetImagesForTest() const { 558 internal::BorderImages* BubbleBorder::GetImagesForTest() const {
543 return images_; 559 return images_;
544 } 560 }
545 561
546 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { 562 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
547 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) 563 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER)
548 canvas->DrawColor(border_->background_color()); 564 canvas->DrawColor(border_->background_color());
549 565
550 // Fill the contents with a round-rect region to match the border images. 566 // Fill the contents with a round-rect region to match the border images.
551 SkPaint paint; 567 SkPaint paint;
552 paint.setAntiAlias(true); 568 paint.setAntiAlias(true);
553 paint.setStyle(SkPaint::kFill_Style); 569 paint.setStyle(SkPaint::kFill_Style);
554 paint.setColor(border_->background_color()); 570 paint.setColor(border_->background_color());
555 SkPath path; 571 SkPath path;
556 gfx::RectF bounds(view->GetLocalBounds()); 572 gfx::RectF bounds(view->GetLocalBounds());
557 bounds.Inset(gfx::InsetsF(border_->GetInsets())); 573 bounds.Inset(gfx::InsetsF(border_->GetInsets()));
558 574
559 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); 575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint);
560 } 576 }
561 577
562 } // namespace views 578 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_border.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698