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

Side by Side Diff: ash/common/frame/header_view.cc

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « ash/common/frame/header_view.h ('k') | ash/common/gpu_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_view.h"
6
7 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h "
8 #include "ash/common/frame/default_header_painter.h"
9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/views/controls/image_view.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17
18 HeaderView::HeaderView(views::Widget* target_widget)
19 : target_widget_(target_widget),
20 header_painter_(new DefaultHeaderPainter),
21 avatar_icon_(nullptr),
22 caption_button_container_(nullptr),
23 fullscreen_visible_fraction_(0) {
24 caption_button_container_ =
25 new FrameCaptionButtonContainerView(target_widget_);
26 caption_button_container_->UpdateSizeButtonVisibility();
27 AddChildView(caption_button_container_);
28
29 header_painter_->Init(target_widget_, this, caption_button_container_);
30 UpdateAvatarIcon();
31
32 WmShell::Get()->AddShellObserver(this);
33 }
34
35 HeaderView::~HeaderView() {
36 WmShell::Get()->RemoveShellObserver(this);
37 }
38
39 void HeaderView::SchedulePaintForTitle() {
40 header_painter_->SchedulePaintForTitle();
41 }
42
43 void HeaderView::ResetWindowControls() {
44 caption_button_container_->ResetWindowControls();
45 }
46
47 int HeaderView::GetPreferredOnScreenHeight() {
48 if (is_immersive_delegate_ && target_widget_->IsFullscreen()) {
49 return static_cast<int>(GetPreferredHeight() *
50 fullscreen_visible_fraction_);
51 }
52 return GetPreferredHeight();
53 }
54
55 int HeaderView::GetPreferredHeight() {
56 // Calculating the preferred height requires at least one Layout().
57 if (!did_layout_)
58 Layout();
59 return header_painter_->GetHeaderHeightForPainting();
60 }
61
62 int HeaderView::GetMinimumWidth() const {
63 return header_painter_->GetMinimumHeaderWidth();
64 }
65
66 void HeaderView::UpdateAvatarIcon() {
67 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
68 WmWindow* window = WmWindow::Get(target_widget_->GetNativeWindow());
69 bool show = delegate->ShouldShowAvatar(window);
70 if (!show) {
71 if (!avatar_icon_)
72 return;
73 delete avatar_icon_;
74 avatar_icon_ = nullptr;
75 } else {
76 gfx::ImageSkia image = delegate->GetAvatarImageForWindow(window);
77 DCHECK_EQ(image.width(), image.height());
78 if (!avatar_icon_) {
79 avatar_icon_ = new views::ImageView();
80 AddChildView(avatar_icon_);
81 }
82 avatar_icon_->SetImage(image);
83 }
84 header_painter_->UpdateLeftHeaderView(avatar_icon_);
85 Layout();
86 }
87
88 void HeaderView::SizeConstraintsChanged() {
89 caption_button_container_->ResetWindowControls();
90 caption_button_container_->UpdateSizeButtonVisibility();
91 Layout();
92 }
93
94 void HeaderView::SetFrameColors(SkColor active_frame_color,
95 SkColor inactive_frame_color) {
96 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color);
97 }
98
99 SkColor HeaderView::GetActiveFrameColor() const {
100 return header_painter_->GetActiveFrameColor();
101 }
102
103 SkColor HeaderView::GetInactiveFrameColor() const {
104 return header_painter_->GetInactiveFrameColor();
105 }
106
107 ///////////////////////////////////////////////////////////////////////////////
108 // HeaderView, views::View overrides:
109
110 void HeaderView::Layout() {
111 did_layout_ = true;
112 header_painter_->LayoutHeader();
113 }
114
115 void HeaderView::OnPaint(gfx::Canvas* canvas) {
116 bool paint_as_active =
117 target_widget_->non_client_view()->frame_view()->ShouldPaintAsActive();
118 caption_button_container_->SetPaintAsActive(paint_as_active);
119
120 HeaderPainter::Mode header_mode = paint_as_active
121 ? HeaderPainter::MODE_ACTIVE
122 : HeaderPainter::MODE_INACTIVE;
123 header_painter_->PaintHeader(canvas, header_mode);
124 }
125
126 void HeaderView::ChildPreferredSizeChanged(views::View* child) {
127 // FrameCaptionButtonContainerView animates the visibility changes in
128 // UpdateSizeButtonVisibility(false). Due to this a new size is not available
129 // until the completion of the animation. Layout in response to the preferred
130 // size changes.
131 if (child != caption_button_container_)
132 return;
133 parent()->Layout();
134 }
135
136 ///////////////////////////////////////////////////////////////////////////////
137 // HeaderView, ShellObserver overrides:
138
139 void HeaderView::OnOverviewModeStarting() {
140 caption_button_container_->SetVisible(false);
141 }
142
143 void HeaderView::OnOverviewModeEnded() {
144 caption_button_container_->SetVisible(true);
145 }
146
147 void HeaderView::OnMaximizeModeStarted() {
148 caption_button_container_->UpdateSizeButtonVisibility();
149 parent()->Layout();
150 }
151
152 void HeaderView::OnMaximizeModeEnded() {
153 caption_button_container_->UpdateSizeButtonVisibility();
154 parent()->Layout();
155 }
156
157 views::View* HeaderView::avatar_icon() const {
158 return avatar_icon_;
159 }
160
161 ///////////////////////////////////////////////////////////////////////////////
162 // HeaderView,
163 // ImmersiveFullscreenControllerDelegate overrides:
164
165 void HeaderView::OnImmersiveRevealStarted() {
166 fullscreen_visible_fraction_ = 0;
167 SetPaintToLayer();
168 parent()->Layout();
169 }
170
171 void HeaderView::OnImmersiveRevealEnded() {
172 fullscreen_visible_fraction_ = 0;
173 DestroyLayer();
174 parent()->Layout();
175 }
176
177 void HeaderView::OnImmersiveFullscreenExited() {
178 fullscreen_visible_fraction_ = 0;
179 DestroyLayer();
180 parent()->Layout();
181 }
182
183 void HeaderView::SetVisibleFraction(double visible_fraction) {
184 if (fullscreen_visible_fraction_ != visible_fraction) {
185 fullscreen_visible_fraction_ = visible_fraction;
186 parent()->Layout();
187 }
188 }
189
190 std::vector<gfx::Rect> HeaderView::GetVisibleBoundsInScreen() const {
191 // TODO(pkotwicz): Implement views::View::ConvertRectToScreen().
192 gfx::Rect visible_bounds(GetVisibleBounds());
193 gfx::Point visible_origin_in_screen(visible_bounds.origin());
194 views::View::ConvertPointToScreen(this, &visible_origin_in_screen);
195 std::vector<gfx::Rect> bounds_in_screen;
196 bounds_in_screen.push_back(
197 gfx::Rect(visible_origin_in_screen, visible_bounds.size()));
198 return bounds_in_screen;
199 }
200
201 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/frame/header_view.h ('k') | ash/common/gpu_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698