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