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

Side by Side Diff: chrome/browser/ui/views/status_bubble_views.cc

Issue 568343002: Removed a few manual roundrect path creations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments Created 6 years, 3 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 | « no previous file | ui/views/bubble/bubble_border.cc » ('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 "chrome/browser/ui/views/status_bubble_views.h" 5 #include "chrome/browser/ui/views/status_bubble_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/wm/window_state.h" 9 #include "ash/wm/window_state.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/themes/theme_properties.h" 15 #include "chrome/browser/themes/theme_properties.h"
16 #include "chrome/browser/ui/elide_url.h" 16 #include "chrome/browser/ui/elide_url.h"
17 #include "net/base/net_util.h" 17 #include "net/base/net_util.h"
18 #include "third_party/skia/include/core/SkPaint.h" 18 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkPath.h"
20 #include "third_party/skia/include/core/SkRect.h" 19 #include "third_party/skia/include/core/SkRect.h"
21 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
22 #include "ui/base/theme_provider.h" 21 #include "ui/base/theme_provider.h"
23 #include "ui/gfx/animation/animation_delegate.h" 22 #include "ui/gfx/animation/animation_delegate.h"
24 #include "ui/gfx/animation/linear_animation.h" 23 #include "ui/gfx/animation/linear_animation.h"
25 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/font_list.h" 25 #include "ui/gfx/font_list.h"
27 #include "ui/gfx/point.h" 26 #include "ui/gfx/point.h"
28 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
29 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 void StatusBubbleViews::StatusView::OnPaint(gfx::Canvas* canvas) { 351 void StatusBubbleViews::StatusView::OnPaint(gfx::Canvas* canvas) {
353 SkPaint paint; 352 SkPaint paint;
354 paint.setStyle(SkPaint::kFill_Style); 353 paint.setStyle(SkPaint::kFill_Style);
355 paint.setAntiAlias(true); 354 paint.setAntiAlias(true);
356 SkColor toolbar_color = theme_service_->GetColor( 355 SkColor toolbar_color = theme_service_->GetColor(
357 ThemeProperties::COLOR_TOOLBAR); 356 ThemeProperties::COLOR_TOOLBAR);
358 paint.setColor(toolbar_color); 357 paint.setColor(toolbar_color);
359 358
360 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); 359 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen();
361 360
362 // Figure out how to round the bubble's four corners. 361 SkScalar rad[8] = {};
363 SkScalar rad[8];
364 362
365 // Top Edges - if the bubble is in its bottom position (sticking downwards), 363 // Top Edges - if the bubble is in its bottom position (sticking downwards),
366 // then we square the top edges. Otherwise, we square the edges based on the 364 // then we square the top edges. Otherwise, we square the edges based on the
367 // position of the bubble within the window (the bubble is positioned in the 365 // position of the bubble within the window (the bubble is positioned in the
368 // southeast corner in RTL and in the southwest corner in LTR). 366 // southeast corner in RTL and in the southwest corner in LTR).
369 if (style_ == STYLE_BOTTOM) { 367 if (style_ != STYLE_BOTTOM) {
370 // Top Left corner.
371 rad[0] = 0;
372 rad[1] = 0;
373
374 // Top Right corner.
375 rad[2] = 0;
376 rad[3] = 0;
377 } else {
378 if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) { 368 if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) {
379 // The text is RtL or the bubble is on the right side (but not both). 369 // The text is RtL or the bubble is on the right side (but not both).
380 370
381 // Top Left corner. 371 // Top Left corner.
382 rad[0] = SkIntToScalar(kBubbleCornerRadius); 372 rad[0] = kBubbleCornerRadius;
383 rad[1] = SkIntToScalar(kBubbleCornerRadius); 373 rad[1] = kBubbleCornerRadius;
384 374 } else {
385 // Top Right corner. 375 // Top Right corner.
386 rad[2] = 0; 376 rad[2] = kBubbleCornerRadius;
387 rad[3] = 0; 377 rad[3] = kBubbleCornerRadius;
388 } else {
389 // Top Left corner.
390 rad[0] = 0;
391 rad[1] = 0;
392
393 // Top Right corner.
394 rad[2] = SkIntToScalar(kBubbleCornerRadius);
395 rad[3] = SkIntToScalar(kBubbleCornerRadius);
396 } 378 }
397 } 379 }
398 380
399 // Bottom edges - square these off if the bubble is in its standard position 381 // Bottom edges - Keep these squared off if the bubble is in its standard
400 // (sticking upward). 382 // position (sticking upward).
401 if (style_ == STYLE_STANDARD || style_ == STYLE_STANDARD_RIGHT) { 383 if (style_ != STYLE_STANDARD && style_ != STYLE_STANDARD_RIGHT) {
402 // Bottom Right Corner. 384 // Bottom Right Corner.
403 rad[4] = 0; 385 rad[4] = kBubbleCornerRadius;
404 rad[5] = 0; 386 rad[5] = kBubbleCornerRadius;
405 387
406 // Bottom Left Corner. 388 // Bottom Left Corner.
407 rad[6] = 0; 389 rad[6] = kBubbleCornerRadius;
408 rad[7] = 0; 390 rad[7] = kBubbleCornerRadius;
409 } else {
410 // Bottom Right Corner.
411 rad[4] = SkIntToScalar(kBubbleCornerRadius);
412 rad[5] = SkIntToScalar(kBubbleCornerRadius);
413
414 // Bottom Left Corner.
415 rad[6] = SkIntToScalar(kBubbleCornerRadius);
416 rad[7] = SkIntToScalar(kBubbleCornerRadius);
417 } 391 }
418 392
419 // Draw the bubble's shadow. 393 // Draw the bubble's shadow.
420 int width = popup_bounds.width(); 394 int width = popup_bounds.width();
421 int height = popup_bounds.height(); 395 int height = popup_bounds.height();
422 SkRect rect(gfx::RectToSkRect(gfx::Rect(popup_bounds.size()))); 396 gfx::Rect rect(gfx::Rect(popup_bounds.size()));
423 SkPath shadow_path;
424 shadow_path.addRoundRect(rect, rad, SkPath::kCW_Direction);
425 SkPaint shadow_paint; 397 SkPaint shadow_paint;
426 shadow_paint.setAntiAlias(true); 398 shadow_paint.setAntiAlias(true);
427 shadow_paint.setColor(kShadowColor); 399 shadow_paint.setColor(kShadowColor);
428 canvas->DrawPath(shadow_path, shadow_paint); 400
401 SkRRect rrect;
402 rrect.setRectRadii(RectToSkRect(rect), (const SkVector*)rad);
403 canvas->sk_canvas()->drawRRect(rrect, paint);
429 404
430 // Draw the bubble. 405 // Draw the bubble.
431 rect.set(SkIntToScalar(kShadowThickness), 406 rect.SetRect(SkIntToScalar(kShadowThickness),
432 SkIntToScalar(kShadowThickness), 407 SkIntToScalar(kShadowThickness),
433 SkIntToScalar(width - kShadowThickness), 408 SkIntToScalar(width),
434 SkIntToScalar(height - kShadowThickness)); 409 SkIntToScalar(height));
435 SkPath path; 410 rrect.setRectRadii(RectToSkRect(rect), (const SkVector*)rad);
436 path.addRoundRect(rect, rad, SkPath::kCW_Direction); 411 canvas->sk_canvas()->drawRRect(rrect, paint);
437 canvas->DrawPath(path, paint);
438 412
439 // Draw highlight text and then the text body. In order to make sure the text 413 // Draw highlight text and then the text body. In order to make sure the text
440 // is aligned to the right on RTL UIs, we mirror the text bounds if the 414 // is aligned to the right on RTL UIs, we mirror the text bounds if the
441 // locale is RTL. 415 // locale is RTL.
442 const gfx::FontList font_list; 416 const gfx::FontList font_list;
443 int text_width = std::min( 417 int text_width = std::min(
444 gfx::GetStringWidth(text_, font_list), 418 gfx::GetStringWidth(text_, font_list),
445 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding); 419 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding);
446 int text_height = height - (kShadowThickness * 2); 420 int text_height = height - (kShadowThickness * 2);
447 gfx::Rect body_bounds(kShadowThickness + kTextPositionX, 421 gfx::Rect body_bounds(kShadowThickness + kTextPositionX,
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 void StatusBubbleViews::SetBubbleWidth(int width) { 864 void StatusBubbleViews::SetBubbleWidth(int width) {
891 size_.set_width(width); 865 size_.set_width(width);
892 SetBounds(original_position_.x(), original_position_.y(), 866 SetBounds(original_position_.x(), original_position_.y(),
893 size_.width(), size_.height()); 867 size_.width(), size_.height());
894 } 868 }
895 869
896 void StatusBubbleViews::CancelExpandTimer() { 870 void StatusBubbleViews::CancelExpandTimer() {
897 if (expand_timer_factory_.HasWeakPtrs()) 871 if (expand_timer_factory_.HasWeakPtrs())
898 expand_timer_factory_.InvalidateWeakPtrs(); 872 expand_timer_factory_.InvalidateWeakPtrs();
899 } 873 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/bubble/bubble_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698