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 17namespace { 18 19// Radius of the header's top corners when the window is restored. 20const int kTopCornerRadiusWhenRestored = 2; 21 22// Distance between left edge of the window and the leftmost view. 23const int kDefaultLeftViewXInset = 9; 24 25// Space between the title text and the caption buttons. 26const int kTitleCaptionButtonSpacing = 5; 27 28// Space between window icon and title text. 29const int kTitleIconOffsetX = 5; 30 31// Space between window edge and title text, when there is no icon. 32const int kTitleNoIconOffsetX = 8; 33 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. 40const int kThemeFrameImageInsetX = 5; 41 42} // namespace 43 44namespace ash { 45 46// static 47int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() { 48 return kTopCornerRadiusWhenRestored; 49} 50 51// static 52int HeaderPainterUtil::GetDefaultLeftViewXInset() { 53 return kDefaultLeftViewXInset; 54} 55 56// static 57int HeaderPainterUtil::GetThemeBackgroundXInset() { 58 return kThemeFrameImageInsetX; 59} 60 61// static 62gfx::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); 74} 75 76// static 77bool 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; 88 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); 95} 96 97} // namespace ash 98