Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 BubbleBorder::~BubbleBorder() {} | 181 BubbleBorder::~BubbleBorder() {} |
| 182 | 182 |
| 183 void BubbleBorder::set_paint_arrow(ArrowPaintType value) { | 183 void BubbleBorder::set_paint_arrow(ArrowPaintType value) { |
| 184 if (UseMd()) | 184 if (UseMd()) |
| 185 return; | 185 return; |
| 186 arrow_paint_type_ = value; | 186 arrow_paint_type_ = value; |
| 187 } | 187 } |
| 188 | 188 |
| 189 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect, | 189 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect, |
| 190 const gfx::Size& contents_size) const { | 190 const gfx::Size& contents_size) const { |
| 191 if (UseMd()) { | 191 if (UseMd() && (arrow_ == TOP_RIGHT || arrow_ == TOP_LEFT)) { |
| 192 // In MD, there are no arrows, so positioning logic is significantly | 192 // In MD, there are no arrows, so positioning logic is significantly |
| 193 // simpler. | 193 // simpler. |
| 194 // TODO(estade): handle more anchor positions. | 194 // TODO(estade): handle more anchor positions. |
| 195 gfx::Rect contents_bounds(contents_size); | |
| 195 if (arrow_ == TOP_RIGHT) { | 196 if (arrow_ == TOP_RIGHT) { |
| 196 gfx::Rect contents_bounds(contents_size); | |
| 197 contents_bounds += | 197 contents_bounds += |
| 198 anchor_rect.bottom_right() - contents_bounds.top_right(); | 198 anchor_rect.bottom_right() - contents_bounds.top_right(); |
| 199 contents_bounds.Inset(-GetInsets()); | |
| 200 return contents_bounds; | |
| 201 } | 199 } |
| 200 if (arrow_ == TOP_LEFT) { | |
|
sky
2016/09/29 03:19:54
Does this do the right thing for rtl?
Evan Stade
2016/09/29 17:27:53
yes
| |
| 201 contents_bounds += | |
| 202 anchor_rect.bottom_left() - contents_bounds.origin(); | |
| 203 } | |
| 204 contents_bounds.Inset(-GetInsets()); | |
| 205 return contents_bounds; | |
| 202 } | 206 } |
| 203 | 207 |
| 204 int x = anchor_rect.x(); | 208 int x = anchor_rect.x(); |
| 205 int y = anchor_rect.y(); | 209 int y = anchor_rect.y(); |
| 206 int w = anchor_rect.width(); | 210 int w = anchor_rect.width(); |
| 207 int h = anchor_rect.height(); | 211 int h = anchor_rect.height(); |
| 208 const gfx::Size size(GetSizeForContentsSize(contents_size)); | 212 const gfx::Size size(GetSizeForContentsSize(contents_size)); |
| 209 const int arrow_offset = GetArrowOffset(size); | 213 const int arrow_offset = GetArrowOffset(size); |
| 210 // |arrow_shift| is necessary to visually align the tip of the bubble arrow | 214 // |arrow_shift| is necessary to visually align the tip of the bubble arrow |
| 211 // with the anchor point. This shift is an inverse of the shadow thickness. | 215 // with the anchor point. This shift is an inverse of the shadow thickness. |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // The border is 1px at all scale factors. Leave room for it. It's partially | 514 // The border is 1px at all scale factors. Leave room for it. It's partially |
| 511 // transparent, so we don't want to draw any background underneath it. | 515 // transparent, so we don't want to draw any background underneath it. |
| 512 const SkScalar one_pixel = SkFloatToScalar(1 / canvas->image_scale()); | 516 const SkScalar one_pixel = SkFloatToScalar(1 / canvas->image_scale()); |
| 513 bounds.Inset(gfx::InsetsF(one_pixel)); | 517 bounds.Inset(gfx::InsetsF(one_pixel)); |
| 514 } | 518 } |
| 515 | 519 |
| 516 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); | 520 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); |
| 517 } | 521 } |
| 518 | 522 |
| 519 } // namespace views | 523 } // namespace views |
| OLD | NEW |