Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Unified Diff: ash/wm/caption_buttons/hideable_caption_button_container.cc

Issue 25536010: Make packaged apps use AppNonClientFrameViewAsh when maximized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..288ce4f8bf188ded06103ddd32477e9002257940
--- /dev/null
+++ b/ash/wm/caption_buttons/hideable_caption_button_container.cc
@@ -0,0 +1,148 @@
+// 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.
James Cook 2013/10/02 21:07:55 If this is related to a particular art asset you m
pkotwicz 2013/10/03 20:45:35 The sizes are derived from IDR_AURA_WINDOW_FULLSCR
+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());
pkotwicz 2013/10/03 20:45:35 This code deals with IDR_AURA_WINDOW_FULLSCREEN_SH
+ }
+
+ 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(
James Cook 2013/10/02 21:07:55 Can you add a basic test for this class, something
pkotwicz 2013/10/03 20:45:35 AppBrowserFrameViewAshTest is a sufficiently good
+ int background_id,
+ views::Widget* frame)
+ : background_id_(background_id),
+ frame_(frame) {
+}
+
+HideableCaptionButtonContainer::~HideableCaptionButtonContainer() {
+ frame_->RemoveObserver(this);
+}
+
+void HideableCaptionButtonContainer::ShowButtonWidget() {
+ // Create view with the caption buttons and a widget to host it.
+ button_container_ = new FrameCaptionButtonContainerView(frame_,
pkotwicz 2013/10/02 21:11:08 Note to self: This is wrong. We need to select whi
pkotwicz 2013/10/03 20:45:35 The "Note to self" is wrong. We can assume that mi
+ 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();
James Cook 2013/10/02 21:07:55 It's great you're careful about handling RTL. +1!
+ 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

Powered by Google App Engine
This is Rietveld 408576698