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