OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/frame/custom_frame_view_ash.h" | 5 #include "ash/common/frame/custom_frame_view_ash.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" | 10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 // View which takes up the entire widget and contains the HeaderView. HeaderView | 118 // View which takes up the entire widget and contains the HeaderView. HeaderView |
119 // is a child of OverlayView to avoid creating a larger texture than necessary | 119 // is a child of OverlayView to avoid creating a larger texture than necessary |
120 // when painting the HeaderView to its own layer. | 120 // when painting the HeaderView to its own layer. |
121 class CustomFrameViewAsh::OverlayView : public views::View, | 121 class CustomFrameViewAsh::OverlayView : public views::View, |
122 public views::ViewTargeterDelegate { | 122 public views::ViewTargeterDelegate { |
123 public: | 123 public: |
124 explicit OverlayView(HeaderView* header_view); | 124 explicit OverlayView(HeaderView* header_view); |
125 ~OverlayView() override; | 125 ~OverlayView() override; |
126 | 126 |
| 127 void SetHeaderHeight(base::Optional<int> height); |
| 128 |
127 // views::View: | 129 // views::View: |
128 void Layout() override; | 130 void Layout() override; |
129 | 131 |
130 private: | 132 private: |
131 // views::ViewTargeterDelegate: | 133 // views::ViewTargeterDelegate: |
132 bool DoesIntersectRect(const views::View* target, | 134 bool DoesIntersectRect(const views::View* target, |
133 const gfx::Rect& rect) const override; | 135 const gfx::Rect& rect) const override; |
134 | 136 |
135 HeaderView* header_view_; | 137 HeaderView* header_view_; |
136 | 138 |
| 139 base::Optional<int> header_height_; |
| 140 |
137 DISALLOW_COPY_AND_ASSIGN(OverlayView); | 141 DISALLOW_COPY_AND_ASSIGN(OverlayView); |
138 }; | 142 }; |
139 | 143 |
140 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) | 144 CustomFrameViewAsh::OverlayView::OverlayView(HeaderView* header_view) |
141 : header_view_(header_view) { | 145 : header_view_(header_view) { |
142 AddChildView(header_view); | 146 AddChildView(header_view); |
143 SetEventTargeter( | 147 SetEventTargeter( |
144 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 148 std::unique_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
145 } | 149 } |
146 | 150 |
147 CustomFrameViewAsh::OverlayView::~OverlayView() {} | 151 CustomFrameViewAsh::OverlayView::~OverlayView() {} |
148 | 152 |
| 153 void CustomFrameViewAsh::OverlayView::SetHeaderHeight( |
| 154 base::Optional<int> height) { |
| 155 if (header_height_ == height) |
| 156 return; |
| 157 |
| 158 header_height_ = height; |
| 159 Layout(); |
| 160 } |
| 161 |
149 /////////////////////////////////////////////////////////////////////////////// | 162 /////////////////////////////////////////////////////////////////////////////// |
150 // CustomFrameViewAsh::OverlayView, views::View overrides: | 163 // CustomFrameViewAsh::OverlayView, views::View overrides: |
151 | 164 |
152 void CustomFrameViewAsh::OverlayView::Layout() { | 165 void CustomFrameViewAsh::OverlayView::Layout() { |
153 // Layout |header_view_| because layout affects the result of | 166 // Layout |header_view_| because layout affects the result of |
154 // GetPreferredOnScreenHeight(). | 167 // GetPreferredOnScreenHeight(). |
155 header_view_->Layout(); | 168 header_view_->Layout(); |
156 | 169 |
157 int onscreen_height = header_view_->GetPreferredOnScreenHeight(); | 170 int onscreen_height = header_height_ |
| 171 ? *header_height_ |
| 172 : header_view_->GetPreferredOnScreenHeight(); |
158 if (onscreen_height == 0) { | 173 if (onscreen_height == 0) { |
159 header_view_->SetVisible(false); | 174 header_view_->SetVisible(false); |
160 } else { | 175 } else { |
161 int height = header_view_->GetPreferredHeight(); | 176 const int height = |
| 177 header_height_ ? *header_height_ : header_view_->GetPreferredHeight(); |
162 header_view_->SetBounds(0, onscreen_height - height, width(), height); | 178 header_view_->SetBounds(0, onscreen_height - height, width(), height); |
163 header_view_->SetVisible(true); | 179 header_view_->SetVisible(true); |
164 } | 180 } |
165 } | 181 } |
166 | 182 |
167 /////////////////////////////////////////////////////////////////////////////// | 183 /////////////////////////////////////////////////////////////////////////////// |
168 // CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides: | 184 // CustomFrameViewAsh::OverlayView, views::ViewTargeterDelegate overrides: |
169 | 185 |
170 bool CustomFrameViewAsh::OverlayView::DoesIntersectRect( | 186 bool CustomFrameViewAsh::OverlayView::DoesIntersectRect( |
171 const views::View* target, | 187 const views::View* target, |
172 const gfx::Rect& rect) const { | 188 const gfx::Rect& rect) const { |
173 CHECK_EQ(target, this); | 189 CHECK_EQ(target, this); |
174 // Grab events in the header view. Return false for other events so that they | 190 // Grab events in the header view. Return false for other events so that they |
175 // can be handled by the client view. | 191 // can be handled by the client view. |
176 return header_view_->HitTestRect(rect); | 192 return header_view_->HitTestRect(rect); |
177 } | 193 } |
178 | 194 |
179 //////////////////////////////////////////////////////////////////////////////// | 195 //////////////////////////////////////////////////////////////////////////////// |
180 // CustomFrameViewAsh, public: | 196 // CustomFrameViewAsh, public: |
181 | 197 |
182 // static | 198 // static |
183 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh"; | 199 const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh"; |
184 | 200 |
185 CustomFrameViewAsh::CustomFrameViewAsh( | 201 CustomFrameViewAsh::CustomFrameViewAsh( |
186 views::Widget* frame, | 202 views::Widget* frame, |
187 ImmersiveFullscreenControllerDelegate* immersive_delegate, | 203 ImmersiveFullscreenControllerDelegate* immersive_delegate, |
188 bool enable_immersive) | 204 bool enable_immersive, |
| 205 mojom::WindowStyle window_style) |
189 : frame_(frame), | 206 : frame_(frame), |
190 header_view_(new HeaderView(frame)), | 207 header_view_(new HeaderView(frame, window_style)), |
| 208 overlay_view_(new OverlayView(header_view_)), |
191 immersive_delegate_(immersive_delegate ? immersive_delegate | 209 immersive_delegate_(immersive_delegate ? immersive_delegate |
192 : header_view_) { | 210 : header_view_) { |
193 WmWindow* frame_window = WmWindow::Get(frame->GetNativeWindow()); | 211 WmWindow* frame_window = WmWindow::Get(frame->GetNativeWindow()); |
194 frame_window->InstallResizeHandleWindowTargeter(nullptr); | 212 frame_window->InstallResizeHandleWindowTargeter(nullptr); |
195 // |header_view_| is set as the non client view's overlay view so that it can | 213 // |header_view_| is set as the non client view's overlay view so that it can |
196 // overlay the web contents in immersive fullscreen. | 214 // overlay the web contents in immersive fullscreen. |
197 frame->non_client_view()->SetOverlayView(new OverlayView(header_view_)); | 215 frame->non_client_view()->SetOverlayView(overlay_view_); |
198 frame_window->aura_window()->SetProperty( | 216 frame_window->aura_window()->SetProperty( |
199 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); | 217 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); |
200 | 218 |
201 // A delegate for a more complex way of fullscreening the window may already | 219 // A delegate for a more complex way of fullscreening the window may already |
202 // be set. This is the case for packaged apps. | 220 // be set. This is the case for packaged apps. |
203 wm::WindowState* window_state = frame_window->GetWindowState(); | 221 wm::WindowState* window_state = frame_window->GetWindowState(); |
204 if (!window_state->HasDelegate()) { | 222 if (!window_state->HasDelegate()) { |
205 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( | 223 window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( |
206 new CustomFrameViewAshWindowStateDelegate(window_state, this, | 224 new CustomFrameViewAshWindowStateDelegate(window_state, this, |
207 enable_immersive))); | 225 enable_immersive))); |
208 } | 226 } |
209 } | 227 } |
210 | 228 |
211 CustomFrameViewAsh::~CustomFrameViewAsh() {} | 229 CustomFrameViewAsh::~CustomFrameViewAsh() {} |
212 | 230 |
213 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( | 231 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( |
214 ImmersiveFullscreenController* immersive_fullscreen_controller) { | 232 ImmersiveFullscreenController* immersive_fullscreen_controller) { |
215 immersive_fullscreen_controller->Init(immersive_delegate_, frame_, | 233 immersive_fullscreen_controller->Init(immersive_delegate_, frame_, |
216 header_view_); | 234 header_view_); |
217 } | 235 } |
218 | 236 |
219 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, | 237 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, |
220 SkColor inactive_frame_color) { | 238 SkColor inactive_frame_color) { |
221 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); | 239 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); |
222 WmWindow* frame_window = WmWindow::Get(frame_->GetNativeWindow()); | 240 WmWindow* frame_window = WmWindow::Get(frame_->GetNativeWindow()); |
223 frame_window->aura_window()->SetProperty( | 241 frame_window->aura_window()->SetProperty( |
224 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); | 242 aura::client::kTopViewColor, header_view_->GetInactiveFrameColor()); |
225 } | 243 } |
226 | 244 |
| 245 void CustomFrameViewAsh::SetHeaderHeight(base::Optional<int> height) { |
| 246 overlay_view_->SetHeaderHeight(height); |
| 247 } |
| 248 |
227 //////////////////////////////////////////////////////////////////////////////// | 249 //////////////////////////////////////////////////////////////////////////////// |
228 // CustomFrameViewAsh, views::NonClientFrameView overrides: | 250 // CustomFrameViewAsh, views::NonClientFrameView overrides: |
229 | 251 |
230 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { | 252 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { |
231 gfx::Rect client_bounds = bounds(); | 253 gfx::Rect client_bounds = bounds(); |
232 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | 254 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
233 return client_bounds; | 255 return client_bounds; |
234 } | 256 } |
235 | 257 |
236 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( | 258 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 FrameCaptionButtonContainerView* | 375 FrameCaptionButtonContainerView* |
354 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { | 376 CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { |
355 return header_view_->caption_button_container(); | 377 return header_view_->caption_button_container(); |
356 } | 378 } |
357 | 379 |
358 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 380 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
359 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 381 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
360 } | 382 } |
361 | 383 |
362 } // namespace ash | 384 } // namespace ash |
OLD | NEW |