| Index: ash/wm/caption_buttons/hideable_caption_button_container.cc
|
| diff --git a/ash/wm/caption_buttons/hideable_caption_button_container.cc b/ash/wm/caption_buttons/hideable_caption_button_container.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e212f2f27f9212dc1b353c32307b760d604a39ee
|
| --- /dev/null
|
| +++ b/ash/wm/caption_buttons/hideable_caption_button_container.cc
|
| @@ -0,0 +1,154 @@
|
| +// Copyright 2013 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/wm/caption_buttons/hideable_caption_button_container.h"
|
| +
|
| +#include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
|
| +#include "base/i18n/rtl.h"
|
| +#include "grit/ash_resources.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/image/image.h"
|
| +#include "ui/gfx/rect.h"
|
| +#include "ui/views/background.h"
|
| +#include "ui/views/border.h"
|
| +#include "ui/views/widget/widget.h"
|
| +
|
| +namespace ash {
|
| +
|
| +namespace {
|
| +
|
| +// The size of the shadow around the caption buttons. The size is based on
|
| +// IDR_AURA_WINDOW_FULLSCREEN_SHADOW.
|
| +const int kShadowSizeX = 16;
|
| +const int kShadowSizeBottom = 21;
|
| +
|
| +// The border for |button_widget_|.
|
| +class HideableCaptionButtonContainerBorder : public views::Border {
|
| + public:
|
| + HideableCaptionButtonContainerBorder() {
|
| + int border_id = base::i18n::IsRTL() ?
|
| + IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL :
|
| + IDR_AURA_WINDOW_FULLSCREEN_SHADOW;
|
| + border_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
|
| + border_id).AsImageSkia();
|
| + }
|
| +
|
| + virtual ~HideableCaptionButtonContainerBorder() {
|
| + }
|
| +
|
| + private:
|
| + // views::Border overrides:
|
| + virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE {
|
| + canvas->DrawImageInt(border_, 0, view.height() - border_.height());
|
| + }
|
| +
|
| + virtual gfx::Insets GetInsets() const OVERRIDE {
|
| + return gfx::Insets(0, kShadowSizeX, kShadowSizeBottom, 0);
|
| + }
|
| +
|
| + gfx::ImageSkia border_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HideableCaptionButtonContainerBorder);
|
| +};
|
| +
|
| +// The background for |button_widget_|.
|
| +class HideableCaptionButtonContainerBackground : public views::Background {
|
| + public:
|
| + explicit HideableCaptionButtonContainerBackground(int background_id) {
|
| + background_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
|
| + background_id).AsImageSkia();
|
| + }
|
| +
|
| + virtual ~HideableCaptionButtonContainerBackground() {
|
| + }
|
| +
|
| + private:
|
| + // views::Background override:
|
| + virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
|
| + gfx::Rect paint_bounds(view->GetContentsBounds());
|
| + paint_bounds.set_x(view->GetMirroredXForRect(paint_bounds));
|
| + canvas->TileImageInt(background_, paint_bounds.x(), paint_bounds.y(),
|
| + paint_bounds.width(), paint_bounds.height());
|
| + }
|
| +
|
| + gfx::ImageSkia background_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(HideableCaptionButtonContainerBackground);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +const char HideableCaptionButtonContainer::kButtonWindowName[] =
|
| + "HideableCaptionButtonContainerWidget";
|
| +
|
| +HideableCaptionButtonContainer::HideableCaptionButtonContainer(
|
| + int background_id,
|
| + views::Widget* frame)
|
| + : background_id_(background_id),
|
| + frame_(frame) {
|
| +}
|
| +
|
| +HideableCaptionButtonContainer::~HideableCaptionButtonContainer() {
|
| + frame_->RemoveObserver(this);
|
| +}
|
| +
|
| +void HideableCaptionButtonContainer::ShowButtonWidget() {
|
| + DCHECK(frame_->IsMaximized());
|
| +
|
| + // Create view with the caption buttons and a widget to host it.
|
| + //
|
| + // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume
|
| + // that the |frame_| can be minimized because it can be maximized.
|
| + button_container_ = new FrameCaptionButtonContainerView(frame_,
|
| + ash::FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
|
| + button_container_->set_header_style(
|
| + ash::FrameCaptionButtonContainerView::HEADER_STYLE_MAXIMIZED_HOSTED_APP);
|
| + button_container_->set_border(new HideableCaptionButtonContainerBorder());
|
| + button_container_->set_background(
|
| + new HideableCaptionButtonContainerBackground(background_id_));
|
| +
|
| + button_widget_.reset(new views::Widget);
|
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
|
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
| + params.parent = frame_->GetNativeWindow();
|
| + params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
|
| + button_widget_->Init(params);
|
| + button_widget_->SetContentsView(button_container_);
|
| + button_widget_->GetNativeWindow()->SetName(kButtonWindowName);
|
| +
|
| + // The shadow border needs to be excluded from the hit test area.
|
| + gfx::Insets hit_test_insets(button_container_->GetInsets());
|
| + if (base::i18n::IsRTL()) {
|
| + hit_test_insets = gfx::Insets(hit_test_insets.top(),
|
| + hit_test_insets.right(),
|
| + hit_test_insets.bottom(),
|
| + hit_test_insets.left());
|
| + }
|
| + button_widget_->GetNativeWindow()->SetHitTestBoundsOverrideOuter(
|
| + hit_test_insets, hit_test_insets);
|
| +
|
| + button_widget_->SetBounds(GetButtonWidgetBounds());
|
| + button_widget_->Show();
|
| +
|
| + frame_->AddObserver(this);
|
| +}
|
| +
|
| +gfx::Rect HideableCaptionButtonContainer::GetButtonWidgetBounds() const {
|
| + gfx::Size size(button_container_->GetPreferredSize());
|
| + gfx::Rect frame_bounds(frame_->GetNativeWindow()->bounds());
|
| + int x = base::i18n::IsRTL() ? 0 : frame_bounds.width() - size.width();
|
| + return gfx::Rect(x, 0, size.width(), size.height());
|
| +}
|
| +
|
| +void HideableCaptionButtonContainer::OnWidgetBoundsChanged(
|
| + views::Widget* widget,
|
| + const gfx::Rect& new_bounds) {
|
| + DCHECK_EQ(frame_, widget);
|
| + button_widget_->SetBounds(GetButtonWidgetBounds());
|
| +}
|
| +
|
| +} // namespace ash
|
|
|