| 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/common/frame/header_painter_util.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "ash/common/wm_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" | |
| 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 leftmost view. | |
| 23 const int kLeftViewXInset = 9; | |
| 24 | |
| 25 // Space between the title text and the caption buttons. | |
| 26 const int kTitleCaptionButtonSpacing = 5; | |
| 27 | |
| 28 // Space between window icon and title text. | |
| 29 const int kTitleIconOffsetX = 5; | |
| 30 | |
| 31 // Space between window edge and title text, when there is no icon. | |
| 32 const 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. | |
| 40 const int kThemeFrameImageInsetX = 5; | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 namespace ash { | |
| 45 | |
| 46 // static | |
| 47 int HeaderPainterUtil::GetTopCornerRadiusWhenRestored() { | |
| 48 return kTopCornerRadiusWhenRestored; | |
| 49 } | |
| 50 | |
| 51 // static | |
| 52 int HeaderPainterUtil::GetLeftViewXInset() { | |
| 53 return kLeftViewXInset; | |
| 54 } | |
| 55 | |
| 56 // static | |
| 57 int HeaderPainterUtil::GetThemeBackgroundXInset() { | |
| 58 return kThemeFrameImageInsetX; | |
| 59 } | |
| 60 | |
| 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); | |
| 74 } | |
| 75 | |
| 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 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | |
| 86 // TODO(sky): GetParent()->GetLayer() is for mash until animations ported. | |
| 87 if (!window || !window->GetParent() || !window->GetParent()->GetLayer()) | |
| 88 return true; | |
| 89 | |
| 90 ui::LayerAnimator* parent_layer_animator = | |
| 91 window->GetParent()->GetLayer()->GetAnimator(); | |
| 92 return !parent_layer_animator->IsAnimatingProperty( | |
| 93 ui::LayerAnimationElement::OPACITY) && | |
| 94 !parent_layer_animator->IsAnimatingProperty( | |
| 95 ui::LayerAnimationElement::VISIBILITY); | |
| 96 } | |
| 97 | |
| 98 } // namespace ash | |
| OLD | NEW |