| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/frame/header_painter_util.h" | 5 #include "ash/frame/header_painter_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
| 11 #include "ui/compositor/layer_animator.h" | 11 #include "ui/compositor/layer_animator.h" |
| 12 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" |
| 13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 14 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Radius of the header's top corners when the window is restored. | 19 // Radius of the header's top corners when the window is restored. |
| 20 const int kTopCornerRadiusWhenRestored = 2; | 20 const int kTopCornerRadiusWhenRestored = 2; |
| 21 | 21 |
| 22 // Distance between left edge of the window and the header icon. | 22 // Distance between left edge of the window and the leftmost view. |
| 23 const int kIconXOffset = 9; | 23 const int kDefaultLeftViewXInset = 9; |
| 24 | |
| 25 // Default height and width of header icon. | |
| 26 const int kDefaultIconSize = 16; | |
| 27 | 24 |
| 28 // Space between the title text and the caption buttons. | 25 // Space between the title text and the caption buttons. |
| 29 const int kTitleCaptionButtonSpacing = 5; | 26 const int kTitleCaptionButtonSpacing = 5; |
| 30 | 27 |
| 31 // Space between window icon and title text. | 28 // Space between window icon and title text. |
| 32 const int kTitleIconOffsetX = 5; | 29 const int kTitleIconOffsetX = 5; |
| 33 | 30 |
| 34 // Space between window edge and title text, when there is no icon. | 31 // Space between window edge and title text, when there is no icon. |
| 35 const int kTitleNoIconOffsetX = 8; | 32 const int kTitleNoIconOffsetX = 8; |
| 36 | 33 |
| 37 // In the pre-Ash era the web content area had a frame along the left edge, so | 34 // In the pre-Ash era the web content area had a frame along the left edge, so |
| 38 // user-generated theme images for the new tab page assume they are shifted | 35 // user-generated theme images for the new tab page assume they are shifted |
| 39 // right relative to the header. Now that we have removed the left edge frame | 36 // right relative to the header. Now that we have removed the left edge frame |
| 40 // we need to copy the theme image for the window header from a few pixels | 37 // we need to copy the theme image for the window header from a few pixels |
| 41 // inset to preserve alignment with the NTP image, or else we'll break a bunch | 38 // inset to preserve alignment with the NTP image, or else we'll break a bunch |
| 42 // of existing themes. We do something similar on OS X for the same reason. | 39 // of existing themes. We do something similar on OS X for the same reason. |
| 43 const int kThemeFrameImageInsetX = 5; | 40 const int kThemeFrameImageInsetX = 5; |
| 44 | 41 |
| 45 } // namespace | 42 } // namespace |
| 46 | 43 |
| 47 namespace ash { | 44 namespace ash { |
| 48 | 45 |
| 49 // static | 46 // static |
| 50 int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() { | 47 int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() { |
| 51 return kTopCornerRadiusWhenRestored; | 48 return kTopCornerRadiusWhenRestored; |
| 52 } | 49 } |
| 53 | 50 |
| 54 // static | 51 // static |
| 55 int HeaderPainterUtil::GetIconXOffset() { | 52 int HeaderPainterUtil::GetDefaultLeftViewXInset() { |
| 56 return kIconXOffset; | 53 return kDefaultLeftViewXInset; |
| 57 } | 54 } |
| 58 | 55 |
| 59 // static | 56 // static |
| 60 int HeaderPainterUtil::GetDefaultIconSize() { | |
| 61 return kDefaultIconSize; | |
| 62 } | |
| 63 | |
| 64 // static | |
| 65 int HeaderPainterUtil::GetThemeBackgroundXInset() { | 57 int HeaderPainterUtil::GetThemeBackgroundXInset() { |
| 66 return kThemeFrameImageInsetX; | 58 return kThemeFrameImageInsetX; |
| 67 } | 59 } |
| 68 | 60 |
| 69 // static | 61 // static |
| 70 gfx::Rect HeaderPainterUtil::GetTitleBounds( | 62 gfx::Rect HeaderPainterUtil::GetTitleBounds( |
| 71 const views::View* icon, | 63 const views::View* left_view, |
| 72 const views::View* caption_button_container, | 64 const views::View* right_view, |
| 73 const gfx::FontList& title_font_list) { | 65 const gfx::FontList& title_font_list) { |
| 74 int x = icon ? | 66 int x = left_view ? left_view->bounds().right() + kTitleIconOffsetX |
| 75 icon->bounds().right() + kTitleIconOffsetX : kTitleNoIconOffsetX; | 67 : kTitleNoIconOffsetX; |
| 76 int height = title_font_list.GetHeight(); | 68 int height = title_font_list.GetHeight(); |
| 77 // Floor when computing the center of |caption_button_container| and when | 69 // Floor when computing the center of |caption_button_container| and when |
| 78 // computing the center of the text. | 70 // computing the center of the text. |
| 79 int y = std::max(0, (caption_button_container->height() / 2) - (height / 2)); | 71 int y = std::max(0, (right_view->height() / 2) - (height / 2)); |
| 80 int width = std::max( | 72 int width = std::max(0, right_view->x() - kTitleCaptionButtonSpacing - x); |
| 81 0, caption_button_container->x() - kTitleCaptionButtonSpacing - x); | |
| 82 return gfx::Rect(x, y, width, height); | 73 return gfx::Rect(x, y, width, height); |
| 83 } | 74 } |
| 84 | 75 |
| 85 // static | 76 // static |
| 86 bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) { | 77 bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) { |
| 87 // Do not animate the header if the parent (e.g. | 78 // Do not animate the header if the parent (e.g. |
| 88 // kShellWindowId_DefaultContainer) is already animating. All of the | 79 // kShellWindowId_DefaultContainer) is already animating. All of the |
| 89 // implementers of HeaderPainter animate activation by continuously painting | 80 // implementers of HeaderPainter animate activation by continuously painting |
| 90 // during the animation. This gives the parent's animation a slower frame | 81 // during the animation. This gives the parent's animation a slower frame |
| 91 // rate. | 82 // rate. |
| 92 // TODO(sky): Expose a better way to determine this rather than assuming the | 83 // TODO(sky): Expose a better way to determine this rather than assuming the |
| 93 // parent is a toplevel container. | 84 // parent is a toplevel container. |
| 94 aura::Window* window = widget->GetNativeWindow(); | 85 aura::Window* window = widget->GetNativeWindow(); |
| 95 if (!window->parent()) | 86 if (!window->parent()) |
| 96 return true; | 87 return true; |
| 97 | 88 |
| 98 ui::LayerAnimator* parent_layer_animator = | 89 ui::LayerAnimator* parent_layer_animator = |
| 99 window->parent()->layer()->GetAnimator(); | 90 window->parent()->layer()->GetAnimator(); |
| 100 return !parent_layer_animator->IsAnimatingProperty( | 91 return !parent_layer_animator->IsAnimatingProperty( |
| 101 ui::LayerAnimationElement::OPACITY) && | 92 ui::LayerAnimationElement::OPACITY) && |
| 102 !parent_layer_animator->IsAnimatingProperty( | 93 !parent_layer_animator->IsAnimatingProperty( |
| 103 ui::LayerAnimationElement::VISIBILITY); | 94 ui::LayerAnimationElement::VISIBILITY); |
| 104 } | 95 } |
| 105 | 96 |
| 106 } // namespace ash | 97 } // namespace ash |
| OLD | NEW |