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

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

Issue 12310022: More flexibility in BubbleBorder arrow rendering. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address msw style nits. Created 7 years, 10 months 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') | ui/views/bubble/tray_bubble_view.h » ('j') | 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> // 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 int corner_radius; 129 int corner_radius;
130 }; 130 };
131 131
132 // static 132 // static
133 struct BubbleBorder::BorderImages* 133 struct BubbleBorder::BorderImages*
134 BubbleBorder::border_images_[SHADOW_COUNT] = { NULL }; 134 BubbleBorder::border_images_[SHADOW_COUNT] = { NULL };
135 135
136 BubbleBorder::BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color) 136 BubbleBorder::BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color)
137 : override_arrow_offset_(0), 137 : override_arrow_offset_(0),
138 arrow_location_(arrow), 138 arrow_location_(arrow),
139 paint_arrow_(true), 139 arrow_paint_type_(PAINT_NORMAL),
140 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), 140 alignment_(ALIGN_ARROW_TO_MID_ANCHOR),
141 background_color_(color) { 141 background_color_(color) {
142 DCHECK(shadow < SHADOW_COUNT); 142 DCHECK(shadow < SHADOW_COUNT);
143 images_ = GetBorderImages(shadow); 143 images_ = GetBorderImages(shadow);
144 144
145 // Calculate horizontal and vertical insets for arrow by ensuring that 145 // Calculate horizontal and vertical insets for arrow by ensuring that
146 // the widest arrow and corner images will have enough room to avoid overlap 146 // the widest arrow and corner images will have enough room to avoid overlap
147 int offset_x = 147 int offset_x =
148 (std::max(images_->top_arrow.width(), 148 (std::max(images_->top_arrow.width(),
149 images_->bottom_arrow.width()) / 2) + 149 images_->bottom_arrow.width()) / 2) +
(...skipping 25 matching lines...) Expand all
175 border_size.set_height(std::max(border_size.height(), 2 * arrow_offset_)); 175 border_size.set_height(std::max(border_size.height(), 2 * arrow_offset_));
176 176
177 // Screen position depends on the arrow location. 177 // Screen position depends on the arrow location.
178 // The bubble should overlap the target by some amount since there is space 178 // The bubble should overlap the target by some amount since there is space
179 // for shadow between arrow tip/bubble border and image bounds. 179 // for shadow between arrow tip/bubble border and image bounds.
180 int x = position_relative_to.x(); 180 int x = position_relative_to.x();
181 int y = position_relative_to.y(); 181 int y = position_relative_to.y();
182 int w = position_relative_to.width(); 182 int w = position_relative_to.width();
183 int h = position_relative_to.height(); 183 int h = position_relative_to.height();
184 184
185 const int arrow_size = images_->arrow_interior_height + kBorderStrokeSize; 185 const int arrow_size = GetArrowSize();
186 const int arrow_offset = GetArrowOffset(border_size); 186 const int arrow_offset = GetArrowOffset(border_size);
187 187
188 // Calculate bubble x coordinate. 188 // Calculate bubble x coordinate.
189 switch (arrow_location_) { 189 switch (arrow_location_) {
190 case TOP_LEFT: 190 case TOP_LEFT:
191 case BOTTOM_LEFT: 191 case BOTTOM_LEFT:
192 x += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? w / 2 - arrow_offset : 192 x += alignment_ == ALIGN_ARROW_TO_MID_ANCHOR ? w / 2 - arrow_offset :
193 -(images_->left.width() - kBorderStrokeSize); 193 -(images_->left.width() - kBorderStrokeSize);
194 break; 194 break;
195 195
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 313 }
314 314
315 int BubbleBorder::GetBorderThickness() const { 315 int BubbleBorder::GetBorderThickness() const {
316 return images_->border_thickness; 316 return images_->border_thickness;
317 } 317 }
318 318
319 int BubbleBorder::GetBorderCornerRadius() const { 319 int BubbleBorder::GetBorderCornerRadius() const {
320 return images_->corner_radius; 320 return images_->corner_radius;
321 } 321 }
322 322
323 int BubbleBorder::GetArrowSize() const {
324 if (arrow_paint_type_ == PAINT_NONE)
325 return 0;
326 return images_->arrow_interior_height + kBorderStrokeSize;
327 }
328
323 int BubbleBorder::GetArrowOffset(const gfx::Size& border_size) const { 329 int BubbleBorder::GetArrowOffset(const gfx::Size& border_size) const {
324 int arrow_offset = arrow_offset_; 330 int arrow_offset = arrow_offset_;
325 if (override_arrow_offset_) { 331 if (override_arrow_offset_) {
326 arrow_offset = override_arrow_offset_; 332 arrow_offset = override_arrow_offset_;
327 } else if (is_arrow_at_center(arrow_location_)) { 333 } else if (is_arrow_at_center(arrow_location_)) {
328 if (is_arrow_on_horizontal(arrow_location_)) 334 if (is_arrow_on_horizontal(arrow_location_))
329 arrow_offset = border_size.width() / 2; 335 arrow_offset = border_size.width() / 2;
330 else 336 else
331 arrow_offset = border_size.height() / 2; 337 arrow_offset = border_size.height() / 2;
332 } 338 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 if (!is_arrow_at_center(arrow_location_)) { 413 if (!is_arrow_at_center(arrow_location_)) {
408 if (is_arrow_on_horizontal(arrow_location_) && 414 if (is_arrow_on_horizontal(arrow_location_) &&
409 !is_arrow_on_left(arrow_location_)) { 415 !is_arrow_on_left(arrow_location_)) {
410 arrow_offset = view.width() - arrow_offset - 1; 416 arrow_offset = view.width() - arrow_offset - 1;
411 } else if (!is_arrow_on_horizontal(arrow_location_) && 417 } else if (!is_arrow_on_horizontal(arrow_location_) &&
412 !is_arrow_on_top(arrow_location_)) { 418 !is_arrow_on_top(arrow_location_)) {
413 arrow_offset = view.height() - arrow_offset - 1; 419 arrow_offset = view.height() - arrow_offset - 1;
414 } 420 }
415 } 421 }
416 422
417 const ArrowLocation arrow_location = paint_arrow_ ? arrow_location_ : NONE; 423 const ArrowLocation arrow_location =
424 arrow_paint_type_ == PAINT_NORMAL ? arrow_location_ : NONE;
418 425
419 // Left edge. 426 // Left edge.
420 if (arrow_location == LEFT_TOP || 427 if (arrow_location == LEFT_TOP ||
421 arrow_location == LEFT_CENTER || 428 arrow_location == LEFT_CENTER ||
422 arrow_location == LEFT_BOTTOM) { 429 arrow_location == LEFT_BOTTOM) {
423 int start_y = top + tl_height; 430 int start_y = top + tl_height;
424 int before_arrow = 431 int before_arrow =
425 arrow_offset - start_y - images_->left_arrow.height() / 2; 432 arrow_offset - start_y - images_->left_arrow.height() / 2;
426 int after_arrow = height - tl_height - bl_height - 433 int after_arrow = height - tl_height - bl_height -
427 images_->left_arrow.height() - before_arrow; 434 images_->left_arrow.height() - before_arrow;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 paint.setColor(border_->background_color()); 631 paint.setColor(border_->background_color());
625 SkPath path; 632 SkPath path;
626 gfx::Rect bounds(view->GetContentsBounds()); 633 gfx::Rect bounds(view->GetContentsBounds());
627 bounds.Inset(-border_->GetBorderThickness(), -border_->GetBorderThickness()); 634 bounds.Inset(-border_->GetBorderThickness(), -border_->GetBorderThickness());
628 SkScalar radius = SkIntToScalar(border_->GetBorderCornerRadius()); 635 SkScalar radius = SkIntToScalar(border_->GetBorderCornerRadius());
629 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); 636 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
630 canvas->DrawPath(path, paint); 637 canvas->DrawPath(path, paint);
631 } 638 }
632 639
633 } // namespace views 640 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_border.h ('k') | ui/views/bubble/tray_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698