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/wm/custom_frame_view_ash.h" | 5 #include "ash/wm/custom_frame_view_ash.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
9 #include "ash/wm/caption_buttons/frame_maximize_button.h" | 9 #include "ash/wm/caption_buttons/frame_maximize_button.h" |
10 #include "ash/wm/caption_buttons/frame_maximize_button_observer.h" | 10 #include "ash/wm/caption_buttons/frame_maximize_button_observer.h" |
11 #include "ash/wm/frame_border_hit_test_controller.h" | 11 #include "ash/wm/frame_border_hit_test_controller.h" |
12 #include "ash/wm/header_painter.h" | 12 #include "ash/wm/header_painter.h" |
13 #include "ash/wm/immersive_fullscreen_controller.h" | 13 #include "ash/wm/immersive_fullscreen_controller.h" |
14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
15 #include "ash/wm/window_state_delegate.h" | 15 #include "ash/wm/window_state_delegate.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
20 #include "ui/aura/window_observer.h" | 20 #include "ui/aura/window_observer.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 24 #include "ui/gfx/rect_conversions.h" |
24 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
25 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
26 #include "ui/views/widget/native_widget_aura.h" | 27 #include "ui/views/widget/native_widget_aura.h" |
27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
28 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
29 #include "ui/views/widget/widget_deletion_observer.h" | 30 #include "ui/views/widget/widget_deletion_observer.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const gfx::Font& GetTitleFont() { | 34 const gfx::Font& GetTitleFont() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Returns the view's preferred height. | 154 // Returns the view's preferred height. |
154 int GetPreferredHeight() const; | 155 int GetPreferredHeight() const; |
155 | 156 |
156 // Returns the view's minimum width. | 157 // Returns the view's minimum width. |
157 int GetMinimumWidth() const; | 158 int GetMinimumWidth() const; |
158 | 159 |
159 // views::View overrides: | 160 // views::View overrides: |
160 virtual void Layout() OVERRIDE; | 161 virtual void Layout() OVERRIDE; |
161 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 162 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
162 | 163 |
163 // Sets whether the header should be painted as active. | |
164 void set_paint_as_active(bool paint_as_active) { | |
165 paint_as_active_ = paint_as_active; | |
166 } | |
167 | |
168 HeaderPainter* header_painter() { | 164 HeaderPainter* header_painter() { |
169 return header_painter_.get(); | 165 return header_painter_.get(); |
170 } | 166 } |
171 | 167 |
172 private: | 168 private: |
173 // ImmersiveFullscreenController::Delegate overrides: | 169 // ImmersiveFullscreenController::Delegate overrides: |
174 virtual void OnImmersiveRevealStarted() OVERRIDE; | 170 virtual void OnImmersiveRevealStarted() OVERRIDE; |
175 virtual void OnImmersiveRevealEnded() OVERRIDE; | 171 virtual void OnImmersiveRevealEnded() OVERRIDE; |
176 virtual void OnImmersiveFullscreenExited() OVERRIDE; | 172 virtual void OnImmersiveFullscreenExited() OVERRIDE; |
177 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; | 173 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
189 // View which contains the window caption buttons. | 185 // View which contains the window caption buttons. |
190 FrameCaptionButtonContainerView* caption_button_container_; | 186 FrameCaptionButtonContainerView* caption_button_container_; |
191 | 187 |
192 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have | 188 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have |
193 // been already destroyed. | 189 // been already destroyed. |
194 views::Widget* maximize_bubble_; | 190 views::Widget* maximize_bubble_; |
195 | 191 |
196 // Keeps track of whether |maximize_bubble_| is still alive. | 192 // Keeps track of whether |maximize_bubble_| is still alive. |
197 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; | 193 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; |
198 | 194 |
199 // Whether the header should be painted as active. | |
200 bool paint_as_active_; | |
201 | |
202 // The fraction of the header's height which is visible while in fullscreen. | 195 // The fraction of the header's height which is visible while in fullscreen. |
203 // This value is meaningless when not in fullscreen. | 196 // This value is meaningless when not in fullscreen. |
204 double fullscreen_visible_fraction_; | 197 double fullscreen_visible_fraction_; |
205 | 198 |
206 DISALLOW_COPY_AND_ASSIGN(HeaderView); | 199 DISALLOW_COPY_AND_ASSIGN(HeaderView); |
207 }; | 200 }; |
208 | 201 |
209 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) | 202 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) |
210 : frame_(frame), | 203 : frame_(frame), |
211 header_painter_(new ash::HeaderPainter), | 204 header_painter_(new ash::HeaderPainter), |
212 caption_button_container_(NULL), | 205 caption_button_container_(NULL), |
213 maximize_bubble_(NULL), | 206 maximize_bubble_(NULL), |
214 paint_as_active_(false), | |
215 fullscreen_visible_fraction_(0) { | 207 fullscreen_visible_fraction_(0) { |
216 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume | 208 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume |
217 // that the window frame can be minimized if it can be maximized. | 209 // that the window frame can be minimized if it can be maximized. |
218 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = | 210 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = |
219 frame_->widget_delegate()->CanMaximize() ? | 211 frame_->widget_delegate()->CanMaximize() ? |
220 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : | 212 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : |
221 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; | 213 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; |
222 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, | 214 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, |
223 minimize_allowed); | 215 minimize_allowed); |
224 AddChildView(caption_button_container_); | 216 AddChildView(caption_button_container_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 257 |
266 void CustomFrameViewAsh::HeaderView::Layout() { | 258 void CustomFrameViewAsh::HeaderView::Layout() { |
267 header_painter_->LayoutHeader(true); | 259 header_painter_->LayoutHeader(true); |
268 header_painter_->set_header_height(GetPreferredHeight()); | 260 header_painter_->set_header_height(GetPreferredHeight()); |
269 } | 261 } |
270 | 262 |
271 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { | 263 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { |
272 int theme_image_id = 0; | 264 int theme_image_id = 0; |
273 if (frame_->IsMaximized() || frame_->IsFullscreen()) | 265 if (frame_->IsMaximized() || frame_->IsFullscreen()) |
274 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_MINIMAL; | 266 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_MINIMAL; |
275 else if (paint_as_active_) | 267 else if (frame_->non_client_view()->frame_view()->ShouldPaintAsActive()) |
276 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | 268 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; |
277 else | 269 else |
278 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; | 270 theme_image_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; |
279 | 271 |
280 header_painter_->PaintHeader( | 272 header_painter_->PaintHeader( |
281 canvas, | 273 canvas, |
282 theme_image_id, | 274 theme_image_id, |
283 0); | 275 0); |
284 header_painter_->PaintTitleBar(canvas, GetTitleFont()); | 276 header_painter_->PaintTitleBar(canvas, GetTitleFont()); |
285 header_painter_->PaintHeaderContentSeparator(canvas); | 277 header_painter_->PaintHeaderContentSeparator(canvas); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 NonClientTopBorderHeight() + min_client_view_size.height()); | 462 NonClientTopBorderHeight() + min_client_view_size.height()); |
471 } | 463 } |
472 | 464 |
473 gfx::Size CustomFrameViewAsh::GetMaximumSize() { | 465 gfx::Size CustomFrameViewAsh::GetMaximumSize() { |
474 return frame_->client_view()->GetMaximumSize(); | 466 return frame_->client_view()->GetMaximumSize(); |
475 } | 467 } |
476 | 468 |
477 void CustomFrameViewAsh::SchedulePaintInRect(const gfx::Rect& r) { | 469 void CustomFrameViewAsh::SchedulePaintInRect(const gfx::Rect& r) { |
478 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint to | 470 // The HeaderView is not a child of CustomFrameViewAsh. Redirect the paint to |
479 // HeaderView instead. | 471 // HeaderView instead. |
480 header_view_->set_paint_as_active(ShouldPaintAsActive()); | 472 gfx::RectF to_paint(r); |
481 header_view_->SchedulePaint(); | 473 views::View::ConvertRectToTarget(this, header_view_, &to_paint); |
| 474 header_view_->SchedulePaintInRect(gfx::ToEnclosingRect(to_paint)); |
482 } | 475 } |
483 | 476 |
484 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { | 477 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { |
485 // NonClientView hit tests the NonClientFrameView first instead of going in | 478 // NonClientView hit tests the NonClientFrameView first instead of going in |
486 // z-order. Return false so that events get to the OverlayView. | 479 // z-order. Return false so that events get to the OverlayView. |
487 return false; | 480 return false; |
488 } | 481 } |
489 | 482 |
490 views::View* CustomFrameViewAsh::GetHeaderView() { | 483 views::View* CustomFrameViewAsh::GetHeaderView() { |
491 return header_view_; | 484 return header_view_; |
492 } | 485 } |
493 | 486 |
494 //////////////////////////////////////////////////////////////////////////////// | 487 //////////////////////////////////////////////////////////////////////////////// |
495 // CustomFrameViewAsh, private: | 488 // CustomFrameViewAsh, private: |
496 | 489 |
497 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 490 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
498 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 491 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
499 } | 492 } |
500 | 493 |
501 } // namespace ash | 494 } // namespace ash |
OLD | NEW |