summaryrefslogtreecommitdiffstats
path: root/ash/frame/header_painter_util.cc
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 21:18:53 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 21:18:53 +0000
commit8f9a4f94342c5da809f4976c81bc8e9bd84cde41 (patch)
tree199be3f2b3030105ca22ff01ca1153a94d5b2917 /ash/frame/header_painter_util.cc
parentbe6d25abdc7019ac2d12cc0b76e709de83a444ef (diff)
downloadchromium_src-8f9a4f94342c5da809f4976c81bc8e9bd84cde41.zip
chromium_src-8f9a4f94342c5da809f4976c81bc8e9bd84cde41.tar.gz
chromium_src-8f9a4f94342c5da809f4976c81bc8e9bd84cde41.tar.bz2
[Refactor] Move code for painting the window header for browser windows out of ash
BUG=340143 TEST=None Review URL: https://codereview.chromium.org/189463013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/frame/header_painter_util.cc')
-rw-r--r--ash/frame/header_painter_util.cc107
1 files changed, 107 insertions, 0 deletions
diff --git a/ash/frame/header_painter_util.cc b/ash/frame/header_painter_util.cc
new file mode 100644
index 0000000..77123e6
--- /dev/null
+++ b/ash/frame/header_painter_util.cc
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/frame/header_painter_util.h"
+
+#include <algorithm>
+
+#include "ui/aura/window.h"
+#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_animator.h"
+#include "ui/gfx/font_list.h"
+#include "ui/gfx/rect.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace {
+
+// Radius of the header's top corners when the window is restored.
+const int kTopCornerRadiusWhenRestored = 2;
+
+// Distance between left edge of the window and the header icon.
+const int kIconXOffset = 9;
+
+// Height and width of header icon.
+const int kIconSize = 16;
+
+// Space between the title text and the caption buttons.
+const int kTitleCaptionButtonSpacing = 5;
+
+// Space between window icon and title text.
+const int kTitleIconOffsetX = 5;
+
+// Space between window edge and title text, when there is no icon.
+const int kTitleNoIconOffsetX = 8;
+
+// In the pre-Ash era the web content area had a frame along the left edge, so
+// user-generated theme images for the new tab page assume they are shifted
+// right relative to the header. Now that we have removed the left edge frame
+// we need to copy the theme image for the window header from a few pixels
+// inset to preserve alignment with the NTP image, or else we'll break a bunch
+// of existing themes. We do something similar on OS X for the same reason.
+const int kThemeFrameImageInsetX = 5;
+
+} // namespace
+
+namespace ash {
+
+// static
+int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() {
+ return kTopCornerRadiusWhenRestored;
+}
+
+// static
+int HeaderPainterUtil::GetIconXOffset() {
+ return kIconXOffset;
+}
+
+// static
+int HeaderPainterUtil::GetIconSize() {
+ return kIconSize;
+}
+
+// static
+int HeaderPainterUtil::GetThemeBackgroundXInset() {
+ return kThemeFrameImageInsetX;
+}
+
+// static
+gfx::Rect HeaderPainterUtil::GetTitleBounds(
+ const views::View* icon,
+ const views::View* caption_button_container,
+ const gfx::FontList& title_font_list) {
+ int x = icon ?
+ icon->bounds().right() + kTitleIconOffsetX : kTitleNoIconOffsetX;
+ int height = title_font_list.GetHeight();
+ int y = std::max(
+ 0,
+ static_cast<int>(std::ceil(
+ (caption_button_container->height() - height) / 2.0f)));
+ int width = std::max(
+ 0, caption_button_container->x() - kTitleCaptionButtonSpacing - x);
+ return gfx::Rect(x, y, width, height);
+}
+
+// static
+bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) {
+ // Do not animate the header if the parent (e.g.
+ // kShellWindowId_DefaultContainer) is already animating. All of the
+ // implementers of HeaderPainter animate activation by continuously painting
+ // during the animation. This gives the parent's animation a slower frame
+ // rate.
+ // TODO(sky): Expose a better way to determine this rather than assuming the
+ // parent is a toplevel container.
+ aura::Window* window = widget->GetNativeWindow();
+ if (!window->parent())
+ return true;
+
+ ui::LayerAnimator* parent_layer_animator =
+ window->parent()->layer()->GetAnimator();
+ return !parent_layer_animator->IsAnimatingProperty(
+ ui::LayerAnimationElement::OPACITY) &&
+ !parent_layer_animator->IsAnimatingProperty(
+ ui::LayerAnimationElement::VISIBILITY);
+}
+
+} // namespace ash