| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/frame/header_painter_util.h" | 5 #include "ash/frame/header_painter_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 67 } |
| 68 | 68 |
| 69 // static | 69 // static |
| 70 gfx::Rect HeaderPainterUtil::GetTitleBounds( | 70 gfx::Rect HeaderPainterUtil::GetTitleBounds( |
| 71 const views::View* icon, | 71 const views::View* icon, |
| 72 const views::View* caption_button_container, | 72 const views::View* caption_button_container, |
| 73 const gfx::FontList& title_font_list) { | 73 const gfx::FontList& title_font_list) { |
| 74 int x = icon ? | 74 int x = icon ? |
| 75 icon->bounds().right() + kTitleIconOffsetX : kTitleNoIconOffsetX; | 75 icon->bounds().right() + kTitleIconOffsetX : kTitleNoIconOffsetX; |
| 76 int height = title_font_list.GetHeight(); | 76 int height = title_font_list.GetHeight(); |
| 77 int y = std::max( | 77 // Floor when computing the center of |caption_button_container| and when |
| 78 0, | 78 // computing the center of the text. |
| 79 static_cast<int>(std::ceil( | 79 int y = std::max(0, (caption_button_container->height() / 2) - (height / 2)); |
| 80 (caption_button_container->height() - height) / 2.0f))); | |
| 81 int width = std::max( | 80 int width = std::max( |
| 82 0, caption_button_container->x() - kTitleCaptionButtonSpacing - x); | 81 0, caption_button_container->x() - kTitleCaptionButtonSpacing - x); |
| 83 return gfx::Rect(x, y, width, height); | 82 return gfx::Rect(x, y, width, height); |
| 84 } | 83 } |
| 85 | 84 |
| 86 // static | 85 // static |
| 87 bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) { | 86 bool HeaderPainterUtil::CanAnimateActivation(views::Widget* widget) { |
| 88 // Do not animate the header if the parent (e.g. | 87 // Do not animate the header if the parent (e.g. |
| 89 // kShellWindowId_DefaultContainer) is already animating. All of the | 88 // kShellWindowId_DefaultContainer) is already animating. All of the |
| 90 // implementers of HeaderPainter animate activation by continuously painting | 89 // implementers of HeaderPainter animate activation by continuously painting |
| 91 // during the animation. This gives the parent's animation a slower frame | 90 // during the animation. This gives the parent's animation a slower frame |
| 92 // rate. | 91 // rate. |
| 93 // TODO(sky): Expose a better way to determine this rather than assuming the | 92 // TODO(sky): Expose a better way to determine this rather than assuming the |
| 94 // parent is a toplevel container. | 93 // parent is a toplevel container. |
| 95 aura::Window* window = widget->GetNativeWindow(); | 94 aura::Window* window = widget->GetNativeWindow(); |
| 96 if (!window->parent()) | 95 if (!window->parent()) |
| 97 return true; | 96 return true; |
| 98 | 97 |
| 99 ui::LayerAnimator* parent_layer_animator = | 98 ui::LayerAnimator* parent_layer_animator = |
| 100 window->parent()->layer()->GetAnimator(); | 99 window->parent()->layer()->GetAnimator(); |
| 101 return !parent_layer_animator->IsAnimatingProperty( | 100 return !parent_layer_animator->IsAnimatingProperty( |
| 102 ui::LayerAnimationElement::OPACITY) && | 101 ui::LayerAnimationElement::OPACITY) && |
| 103 !parent_layer_animator->IsAnimatingProperty( | 102 !parent_layer_animator->IsAnimatingProperty( |
| 104 ui::LayerAnimationElement::VISIBILITY); | 103 ui::LayerAnimationElement::VISIBILITY); |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace ash | 106 } // namespace ash |
| OLD | NEW |