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 "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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Figure out how to round the bubble's four corners. |
363 SkScalar rad[8]; | 362 int radTL = 0; |
363 int radTR = 0; | |
364 int radBL = 0; | |
365 int radBR = 0; | |
364 | 366 |
365 // Top Edges - if the bubble is in its bottom position (sticking downwards), | 367 // 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 | 368 // 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 | 369 // 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). | 370 // southeast corner in RTL and in the southwest corner in LTR). |
369 if (style_ == STYLE_BOTTOM) { | 371 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)) { | 372 if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) { |
379 // The text is RtL or the bubble is on the right side (but not both). | 373 // The text is RtL or the bubble is on the right side (but not both). |
380 | 374 radTL = kBubbleCornerRadius; |
381 // Top Left corner. | |
382 rad[0] = SkIntToScalar(kBubbleCornerRadius); | |
383 rad[1] = SkIntToScalar(kBubbleCornerRadius); | |
384 | |
385 // Top Right corner. | |
386 rad[2] = 0; | |
387 rad[3] = 0; | |
388 } else { | 375 } else { |
389 // Top Left corner. | 376 radTR = kBubbleCornerRadius; |
390 rad[0] = 0; | |
391 rad[1] = 0; | |
392 | |
393 // Top Right corner. | |
394 rad[2] = SkIntToScalar(kBubbleCornerRadius); | |
395 rad[3] = SkIntToScalar(kBubbleCornerRadius); | |
396 } | 377 } |
397 } | 378 } |
398 | 379 |
399 // Bottom edges - square these off if the bubble is in its standard position | 380 // Bottom edges - Keep these squared off if the bubble is in its standard |
400 // (sticking upward). | 381 // position (sticking upward). |
401 if (style_ == STYLE_STANDARD || style_ == STYLE_STANDARD_RIGHT) { | 382 if (style_ != STYLE_STANDARD && style_ != STYLE_STANDARD_RIGHT) { |
402 // Bottom Right Corner. | 383 radBR = kBubbleCornerRadius; |
403 rad[4] = 0; | 384 radBL = kBubbleCornerRadius; |
404 rad[5] = 0; | |
405 | |
406 // Bottom Left Corner. | |
407 rad[6] = 0; | |
408 rad[7] = 0; | |
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 } | 385 } |
418 | 386 |
419 // Draw the bubble's shadow. | 387 // Draw the bubble's shadow. |
420 int width = popup_bounds.width(); | 388 int width = popup_bounds.width(); |
421 int height = popup_bounds.height(); | 389 int height = popup_bounds.height(); |
422 SkRect rect(gfx::RectToSkRect(gfx::Rect(popup_bounds.size()))); | 390 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; | 391 SkPaint shadow_paint; |
426 shadow_paint.setAntiAlias(true); | 392 shadow_paint.setAntiAlias(true); |
427 shadow_paint.setColor(kShadowColor); | 393 shadow_paint.setColor(kShadowColor); |
428 canvas->DrawPath(shadow_path, shadow_paint); | 394 canvas->DrawRoundRect(rect, radTL, radTR, radBL, radBR, shadow_paint); |
sky
2014/09/15 19:11:17
This seems to be the only place using this variant
sky
2014/09/15 21:51:07
You should be able to use canvas->sk_canvas()->...
| |
429 | 395 |
430 // Draw the bubble. | 396 // Draw the bubble. |
431 rect.set(SkIntToScalar(kShadowThickness), | 397 rect.SetRect(SkIntToScalar(kShadowThickness), |
432 SkIntToScalar(kShadowThickness), | 398 SkIntToScalar(kShadowThickness), |
433 SkIntToScalar(width - kShadowThickness), | 399 SkIntToScalar(width), |
434 SkIntToScalar(height - kShadowThickness)); | 400 SkIntToScalar(height)); |
435 SkPath path; | 401 canvas->DrawRoundRect(rect, radTL, radTR, radBL, radBR, paint); |
436 path.addRoundRect(rect, rad, SkPath::kCW_Direction); | |
437 canvas->DrawPath(path, paint); | |
438 | 402 |
439 // Draw highlight text and then the text body. In order to make sure the text | 403 // 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 | 404 // is aligned to the right on RTL UIs, we mirror the text bounds if the |
441 // locale is RTL. | 405 // locale is RTL. |
442 const gfx::FontList font_list; | 406 const gfx::FontList font_list; |
443 int text_width = std::min( | 407 int text_width = std::min( |
444 gfx::GetStringWidth(text_, font_list), | 408 gfx::GetStringWidth(text_, font_list), |
445 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding); | 409 width - (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding); |
446 int text_height = height - (kShadowThickness * 2); | 410 int text_height = height - (kShadowThickness * 2); |
447 gfx::Rect body_bounds(kShadowThickness + kTextPositionX, | 411 gfx::Rect body_bounds(kShadowThickness + kTextPositionX, |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 void StatusBubbleViews::SetBubbleWidth(int width) { | 854 void StatusBubbleViews::SetBubbleWidth(int width) { |
891 size_.set_width(width); | 855 size_.set_width(width); |
892 SetBounds(original_position_.x(), original_position_.y(), | 856 SetBounds(original_position_.x(), original_position_.y(), |
893 size_.width(), size_.height()); | 857 size_.width(), size_.height()); |
894 } | 858 } |
895 | 859 |
896 void StatusBubbleViews::CancelExpandTimer() { | 860 void StatusBubbleViews::CancelExpandTimer() { |
897 if (expand_timer_factory_.HasWeakPtrs()) | 861 if (expand_timer_factory_.HasWeakPtrs()) |
898 expand_timer_factory_.InvalidateWeakPtrs(); | 862 expand_timer_factory_.InvalidateWeakPtrs(); |
899 } | 863 } |
OLD | NEW |