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> // for std::max | 7 #include <algorithm> // for std::max |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 struct BubbleBorder::BorderImages* BubbleBorder::normal_images_ = NULL; | 51 struct BubbleBorder::BorderImages* BubbleBorder::normal_images_ = NULL; |
52 struct BubbleBorder::BorderImages* BubbleBorder::shadow_images_ = NULL; | 52 struct BubbleBorder::BorderImages* BubbleBorder::shadow_images_ = NULL; |
53 | 53 |
54 // The height inside the arrow image, in pixels. | 54 // The height inside the arrow image, in pixels. |
55 static const int kArrowInteriorHeight = 7; | 55 static const int kArrowInteriorHeight = 7; |
56 | 56 |
57 BubbleBorder::BubbleBorder(ArrowLocation arrow_location, Shadow shadow) | 57 BubbleBorder::BubbleBorder(ArrowLocation arrow_location, Shadow shadow) |
58 : override_arrow_offset_(0), | 58 : override_arrow_offset_(0), |
59 arrow_location_(arrow_location), | 59 arrow_location_(arrow_location), |
60 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), | 60 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), |
61 background_color_(SK_ColorWHITE) { | 61 background_color_(SK_ColorWHITE), |
62 rtl_mirrored_(true) { | |
62 images_ = GetBorderImages(shadow); | 63 images_ = GetBorderImages(shadow); |
63 | 64 |
64 // Calculate horizontal and vertical insets for arrow by ensuring that | 65 // Calculate horizontal and vertical insets for arrow by ensuring that |
65 // the widest arrow and corner images will have enough room to avoid overlap | 66 // the widest arrow and corner images will have enough room to avoid overlap |
66 int offset_x = | 67 int offset_x = |
67 (std::max(images_->top_arrow->width(), | 68 (std::max(images_->top_arrow->width(), |
68 images_->bottom_arrow->width()) / 2) + | 69 images_->bottom_arrow->width()) / 2) + |
69 std::max(std::max(images_->top_left->width(), | 70 std::max(std::max(images_->top_left->width(), |
70 images_->top_right->width()), | 71 images_->top_right->width()), |
71 std::max(images_->bottom_left->width(), | 72 std::max(images_->bottom_left->width(), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 168 |
168 case FLOAT: | 169 case FLOAT: |
169 y += h / 2 - border_size.height() / 2; | 170 y += h / 2 - border_size.height() / 2; |
170 break; | 171 break; |
171 } | 172 } |
172 | 173 |
173 return gfx::Rect(x, y, border_size.width(), border_size.height()); | 174 return gfx::Rect(x, y, border_size.width(), border_size.height()); |
174 } | 175 } |
175 | 176 |
176 void BubbleBorder::GetInsets(gfx::Insets* insets) const { | 177 void BubbleBorder::GetInsets(gfx::Insets* insets) const { |
178 // Insets will get mirrored in the View code for normal layout. If | |
msw
2012/07/23 22:20:49
Don't you need to update arrow_location() to condi
stevenjb
2012/07/23 23:32:06
See comment below.
| |
179 // rtl_mirrored_ is false, invert the layout here so that when they are | |
180 // mirrored in the View code the insets are correct. | |
181 ArrowLocation arrow_loc = arrow_location_; | |
182 if (!rtl_mirrored_ && base::i18n::IsRTL()) | |
183 arrow_loc = horizontal_mirror(arrow_loc); | |
184 return GetInsetsForArrowLocation(insets, arrow_loc); | |
185 } | |
186 | |
187 void BubbleBorder::GetInsetsForArrowLocation(gfx::Insets* insets, | |
msw
2012/07/23 22:20:49
Can you merge this function back into GetInsets()
stevenjb
2012/07/23 23:32:06
The problem is that most of the code in BubbleBord
msw
2012/07/24 00:32:44
I guess I'm unfamiliar with the use case, but this
| |
188 ArrowLocation arrow_loc) const { | |
177 int top = images_->top->height(); | 189 int top = images_->top->height(); |
178 int bottom = images_->bottom->height(); | 190 int bottom = images_->bottom->height(); |
179 int left = images_->left->width(); | 191 int left = images_->left->width(); |
180 int right = images_->right->width(); | 192 int right = images_->right->width(); |
181 switch (arrow_location_) { | 193 switch (arrow_loc) { |
182 case TOP_LEFT: | 194 case TOP_LEFT: |
183 case TOP_RIGHT: | 195 case TOP_RIGHT: |
184 top = std::max(top, images_->top_arrow->height()); | 196 top = std::max(top, images_->top_arrow->height()); |
185 break; | 197 break; |
186 | 198 |
187 case BOTTOM_LEFT: | 199 case BOTTOM_LEFT: |
188 case BOTTOM_RIGHT: | 200 case BOTTOM_RIGHT: |
189 bottom = std::max(bottom, images_->bottom_arrow->height()); | 201 bottom = std::max(bottom, images_->bottom_arrow->height()); |
190 break; | 202 break; |
191 | 203 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 paint.setColor(border_->background_color()); | 512 paint.setColor(border_->background_color()); |
501 SkPath path; | 513 SkPath path; |
502 gfx::Rect bounds(view->GetContentsBounds()); | 514 gfx::Rect bounds(view->GetContentsBounds()); |
503 bounds.Inset(-border_->border_thickness(), -border_->border_thickness()); | 515 bounds.Inset(-border_->border_thickness(), -border_->border_thickness()); |
504 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 516 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); |
505 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); | 517 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
506 canvas->DrawPath(path, paint); | 518 canvas->DrawPath(path, paint); |
507 } | 519 } |
508 | 520 |
509 } // namespace views | 521 } // namespace views |
OLD | NEW |