OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/frame/header_painter_util.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/compositor/layer.h" |
| 11 #include "ui/compositor/layer_animator.h" |
| 12 #include "ui/gfx/font_list.h" |
| 13 #include "ui/gfx/rect.h" |
| 14 #include "ui/views/view.h" |
| 15 #include "ui/views/widget/widget.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Radius of the header's top corners when the window is restored. |
| 20 const int kTopCornerRadiusWhenRestored = 2; |
| 21 |
| 22 // Distance between left edge of the window and the header icon. |
| 23 const int kIconXOffset = 9; |
| 24 |
| 25 // Height and width of header icon. |
| 26 const int kIconSize = 16; |
| 27 |
| 28 // Space between the title text and the caption buttons. |
| 29 const int kTitleCaptionButtonSpacing = 5; |
| 30 |
| 31 // Space between window icon and title text. |
| 32 const int kTitleIconOffsetX = 5; |
| 33 |
| 34 // Space between window edge and title text, when there is no icon. |
| 35 const int kTitleNoIconOffsetX = 8; |
| 36 |
| 37 // 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 |
| 39 // 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 |
| 41 // 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. |
| 43 const int kThemeFrameImageInsetX = 5; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 namespace ash { |
| 48 |
| 49 // static |
| 50 int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() { |
| 51 return kTopCornerRadiusWhenRestored; |
| 52 } |
| 53 |
| 54 // static |
| 55 int HeaderPainterUtil::GetIconXOffset() { |
| 56 return kIconXOffset; |
| 57 } |
| 58 |
| 59 // static |
| 60 int HeaderPainterUtil::GetIconSize() { |
| 61 return kIconSize; |
| 62 } |
| 63 |
| 64 // static |
| 65 int HeaderPainterUtil::GetThemeBackgroundXInset() { |
| 66 return kThemeFrameImageInsetX; |
| 67 } |
| 68 |
| 69 // static |
| 70 gfx::Rect HeaderPainterUtil::GetTitleBounds( |
| 71 const views::View* icon, |
| 72 const views::View* caption_button_container, |
| 73 const gfx::FontList& title_font_list) { |
| 74 int x = icon ? |
| 75 icon->bounds().right() + kTitleIconOffsetX : kTitleNoIconOffsetX; |
| 76 int height = title_font_list.GetHeight(); |
| 77 int y = std::max( |
| 78 0, |
| 79 static_cast<int>(std::ceil( |
| 80 (caption_button_container->height() - height) / 2.0f))); |
| 81 int width = std::max( |
| 82 0, caption_button_container->x() - kTitleCaptionButtonSpacing - x); |
| 83 return gfx::Rect(x, y, width, height); |
| 84 } |
| 85 |
| 86 // static |
| 87 bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) { |
| 88 // Do not animate the header if the parent (e.g. |
| 89 // kShellWindowId_DefaultContainer) is already animating. All of the |
| 90 // implementers of HeaderPainter animate activation by continuously painting |
| 91 // during the animation. This gives the parent's animation a slower frame |
| 92 // rate. |
| 93 // TODO(sky): Expose a better way to determine this rather than assuming the |
| 94 // parent is a toplevel container. |
| 95 aura::Window* window = widget->GetNativeWindow(); |
| 96 if (!window->parent()) |
| 97 return true; |
| 98 |
| 99 ui::LayerAnimator* parent_layer_animator = |
| 100 window->parent()->layer()->GetAnimator(); |
| 101 return !parent_layer_animator->IsAnimatingProperty( |
| 102 ui::LayerAnimationElement::OPACITY) && |
| 103 !parent_layer_animator->IsAnimatingProperty( |
| 104 ui::LayerAnimationElement::VISIBILITY); |
| 105 } |
| 106 |
| 107 } // namespace ash |
OLD | NEW |