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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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/wm/caption_buttons/hideable_caption_button_container.h"
6
7 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h"
8 #include "base/i18n/rtl.h"
9 #include "grit/ash_resources.h"
10 #include "ui/aura/window.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/views/background.h"
16 #include "ui/views/border.h"
17 #include "ui/views/widget/widget.h"
18
19 namespace ash {
20
21 namespace {
22
23 // 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
24 const int kShadowSizeX = 16;
25 const int kShadowSizeBottom = 21;
26
27 // The border for |button_widget_|.
28 class HideableCaptionButtonContainerBorder : public views::Border {
29 public:
30 HideableCaptionButtonContainerBorder() {
31 int border_id = base::i18n::IsRTL() ?
32 IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL :
33 IDR_AURA_WINDOW_FULLSCREEN_SHADOW;
34 border_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
35 border_id).AsImageSkia();
36 }
37
38 virtual ~HideableCaptionButtonContainerBorder() {
39 }
40
41 private:
42 // views::Border overrides:
43 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE {
44 canvas->DrawImageInt(border_, 0, view.height() - border_.height());
pkotwicz 2013/10/03 20:45:35 This code deals with IDR_AURA_WINDOW_FULLSCREEN_SH
45 }
46
47 virtual gfx::Insets GetInsets() const OVERRIDE {
48 return gfx::Insets(0, kShadowSizeX, kShadowSizeBottom, 0);
49 }
50
51 gfx::ImageSkia border_;
52
53 DISALLOW_COPY_AND_ASSIGN(HideableCaptionButtonContainerBorder);
54 };
55
56 // The background for |button_widget_|.
57 class HideableCaptionButtonContainerBackground : public views::Background {
58 public:
59 explicit HideableCaptionButtonContainerBackground(int background_id) {
60 background_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
61 background_id).AsImageSkia();
62 }
63
64 virtual ~HideableCaptionButtonContainerBackground() {
65 }
66
67 private:
68 // views::Background override:
69 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
70 gfx::Rect paint_bounds(view->GetContentsBounds());
71 paint_bounds.set_x(view->GetMirroredXForRect(paint_bounds));
72 canvas->TileImageInt(background_, paint_bounds.x(), paint_bounds.y(),
73 paint_bounds.width(), paint_bounds.height());
74 }
75
76 gfx::ImageSkia background_;
77
78 DISALLOW_COPY_AND_ASSIGN(HideableCaptionButtonContainerBackground);
79 };
80
81 } // namespace
82
83 // static
84 const char HideableCaptionButtonContainer::kButtonWindowName[] =
85 "HideableCaptionButtonContainerWidget";
86
87 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
88 int background_id,
89 views::Widget* frame)
90 : background_id_(background_id),
91 frame_(frame) {
92 }
93
94 HideableCaptionButtonContainer::~HideableCaptionButtonContainer() {
95 frame_->RemoveObserver(this);
96 }
97
98 void HideableCaptionButtonContainer::ShowButtonWidget() {
99 // Create view with the caption buttons and a widget to host it.
100 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
101 ash::FrameCaptionButtonContainerView::MINIMIZE_ALLOWED);
102 button_container_->set_header_style(
103 ash::FrameCaptionButtonContainerView::HEADER_STYLE_MAXIMIZED_HOSTED_APP);
104 button_container_->set_border(new HideableCaptionButtonContainerBorder());
105 button_container_->set_background(
106 new HideableCaptionButtonContainerBackground(background_id_));
107
108 button_widget_.reset(new views::Widget);
109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
110 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
111 params.parent = frame_->GetNativeWindow();
112 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
113 button_widget_->Init(params);
114 button_widget_->SetContentsView(button_container_);
115 button_widget_->GetNativeWindow()->SetName(kButtonWindowName);
116
117 // The shadow border needs to be excluded from the hit test area.
118 gfx::Insets hit_test_insets(button_container_->GetInsets());
119 if (base::i18n::IsRTL()) {
120 hit_test_insets = gfx::Insets(hit_test_insets.top(),
121 hit_test_insets.right(),
122 hit_test_insets.bottom(),
123 hit_test_insets.left());
124 }
125 button_widget_->GetNativeWindow()->SetHitTestBoundsOverrideOuter(
126 hit_test_insets, hit_test_insets);
127
128 button_widget_->SetBounds(GetButtonWidgetBounds());
129 button_widget_->Show();
130
131 frame_->AddObserver(this);
132 }
133
134 gfx::Rect HideableCaptionButtonContainer::GetButtonWidgetBounds() const {
135 gfx::Size size(button_container_->GetPreferredSize());
136 gfx::Rect frame_bounds(frame_->GetNativeWindow()->bounds());
137 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!
138 return gfx::Rect(x, 0, size.width(), size.height());
139 }
140
141 void HideableCaptionButtonContainer::OnWidgetBoundsChanged(
142 views::Widget* widget,
143 const gfx::Rect& new_bounds) {
144 DCHECK_EQ(frame_, widget);
145 button_widget_->SetBounds(GetButtonWidgetBounds());
146 }
147
148 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698