| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (UseMd() && | 215 if (UseMd() && |
| 216 (arrow_ == TOP_RIGHT || arrow_ == TOP_LEFT || arrow_ == BOTTOM_CENTER || | 216 (arrow_ == TOP_RIGHT || arrow_ == TOP_LEFT || arrow_ == BOTTOM_CENTER || |
| 217 arrow_ == LEFT_CENTER || arrow_ == RIGHT_CENTER)) { | 217 arrow_ == LEFT_CENTER || arrow_ == RIGHT_CENTER)) { |
| 218 gfx::Rect contents_bounds(contents_size); | 218 gfx::Rect contents_bounds(contents_size); |
| 219 // Apply the border part of the inset before calculating coordinates because | 219 // Apply the border part of the inset before calculating coordinates because |
| 220 // the border should align with the anchor's border. For the purposes of | 220 // the border should align with the anchor's border. For the purposes of |
| 221 // positioning, the border is rounded up to a dip, which may mean we have | 221 // positioning, the border is rounded up to a dip, which may mean we have |
| 222 // misalignment in scale factors greater than 1. | 222 // misalignment in scale factors greater than 1. |
| 223 // TODO(estade): when it becomes possible to provide px bounds instead of | 223 // TODO(estade): when it becomes possible to provide px bounds instead of |
| 224 // dip bounds, fix this. | 224 // dip bounds, fix this. |
| 225 const gfx::Insets border_insets = gfx::Insets(kBorderThicknessDip); | 225 const gfx::Insets border_insets = |
| 226 shadow_ == NO_ASSETS ? gfx::Insets() : gfx::Insets(kBorderThicknessDip); |
| 226 const gfx::Insets shadow_insets = GetInsets() - border_insets; | 227 const gfx::Insets shadow_insets = GetInsets() - border_insets; |
| 227 contents_bounds.Inset(-border_insets); | 228 contents_bounds.Inset(-border_insets); |
| 228 if (arrow_ == TOP_RIGHT) { | 229 if (arrow_ == TOP_RIGHT) { |
| 229 contents_bounds += | 230 contents_bounds += |
| 230 anchor_rect.bottom_right() - contents_bounds.top_right(); | 231 anchor_rect.bottom_right() - contents_bounds.top_right(); |
| 231 } else if (arrow_ == TOP_LEFT) { | 232 } else if (arrow_ == TOP_LEFT) { |
| 232 contents_bounds += | 233 contents_bounds += |
| 233 anchor_rect.bottom_left() - contents_bounds.origin(); | 234 anchor_rect.bottom_left() - contents_bounds.origin(); |
| 234 } else if (arrow_ == BOTTOM_CENTER) { | 235 } else if (arrow_ == BOTTOM_CENTER) { |
| 235 contents_bounds += CenterTop(anchor_rect) - CenterBottom(contents_bounds); | 236 contents_bounds += CenterTop(anchor_rect) - CenterBottom(contents_bounds); |
| 236 } else if (arrow_ == LEFT_CENTER) { | 237 } else if (arrow_ == LEFT_CENTER) { |
| 237 contents_bounds += RightCenter(anchor_rect) - LeftCenter(contents_bounds); | 238 contents_bounds += RightCenter(anchor_rect) - LeftCenter(contents_bounds); |
| 238 } else if (arrow_ == RIGHT_CENTER) { | 239 } else if (arrow_ == RIGHT_CENTER) { |
| 239 contents_bounds += LeftCenter(anchor_rect) - RightCenter(contents_bounds); | 240 contents_bounds += LeftCenter(anchor_rect) - RightCenter(contents_bounds); |
| 240 } | 241 } |
| 242 // With NO_ASSETS, there should be further insets, but the same logic is |
| 243 // used to position the bubble origin according to |anchor_rect|. |
| 244 DCHECK(shadow_ != NO_ASSETS || shadow_insets.IsEmpty()); |
| 241 contents_bounds.Inset(-shadow_insets); | 245 contents_bounds.Inset(-shadow_insets); |
| 242 // |arrow_offset_| is used to adjust bubbles that would normally be | 246 // |arrow_offset_| is used to adjust bubbles that would normally be |
| 243 // partially offscreen. | 247 // partially offscreen. |
| 244 contents_bounds += gfx::Vector2d(-arrow_offset_, 0); | 248 contents_bounds += gfx::Vector2d(-arrow_offset_, 0); |
| 245 return contents_bounds; | 249 return contents_bounds; |
| 246 } | 250 } |
| 247 | 251 |
| 248 int x = anchor_rect.x(); | 252 int x = anchor_rect.x(); |
| 249 int y = anchor_rect.y(); | 253 int y = anchor_rect.y(); |
| 250 int w = anchor_rect.width(); | 254 int w = anchor_rect.width(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 366 } |
| 363 | 367 |
| 364 gfx::Insets BubbleBorder::GetInsets() const { | 368 gfx::Insets BubbleBorder::GetInsets() const { |
| 365 if (UseMd()) { | 369 if (UseMd()) { |
| 366 if (shadow_ == NO_ASSETS) | 370 if (shadow_ == NO_ASSETS) |
| 367 return gfx::Insets(); | 371 return gfx::Insets(); |
| 368 | 372 |
| 369 gfx::Insets blur(kLargeShadowBlur); | 373 gfx::Insets blur(kLargeShadowBlur); |
| 370 gfx::Insets offset(-kLargeShadowVerticalOffset, 0, | 374 gfx::Insets offset(-kLargeShadowVerticalOffset, 0, |
| 371 kLargeShadowVerticalOffset, 0); | 375 kLargeShadowVerticalOffset, 0); |
| 372 gfx::Insets border(kBorderThicknessDip); | |
| 373 return blur + offset; | 376 return blur + offset; |
| 374 } | 377 } |
| 375 | 378 |
| 376 // The insets contain the stroke and shadow pixels outside the bubble fill. | 379 // The insets contain the stroke and shadow pixels outside the bubble fill. |
| 377 const int inset = GetBorderThickness(); | 380 const int inset = GetBorderThickness(); |
| 378 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) | 381 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) |
| 379 return gfx::Insets(inset); | 382 return gfx::Insets(inset); |
| 380 | 383 |
| 381 int first_inset = inset; | 384 int first_inset = inset; |
| 382 int second_inset = std::max(inset, images_->arrow_thickness); | 385 int second_inset = std::max(inset, images_->arrow_thickness); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 paint.setStyle(SkPaint::kFill_Style); | 569 paint.setStyle(SkPaint::kFill_Style); |
| 567 paint.setColor(border_->background_color()); | 570 paint.setColor(border_->background_color()); |
| 568 SkPath path; | 571 SkPath path; |
| 569 gfx::RectF bounds(view->GetLocalBounds()); | 572 gfx::RectF bounds(view->GetLocalBounds()); |
| 570 bounds.Inset(gfx::InsetsF(border_->GetInsets())); | 573 bounds.Inset(gfx::InsetsF(border_->GetInsets())); |
| 571 | 574 |
| 572 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); | 575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); |
| 573 } | 576 } |
| 574 | 577 |
| 575 } // namespace views | 578 } // namespace views |
| OLD | NEW |