| 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/panels/panel_frame_view.h" | 5 #include "ash/wm/panels/panel_frame_view.h" |
| 6 | 6 |
| 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 8 #include "ash/frame/default_header_painter.h" |
| 8 #include "ash/frame/frame_border_hit_test_controller.h" | 9 #include "ash/frame/frame_border_hit_test_controller.h" |
| 9 #include "ash/frame/header_painter.h" | |
| 10 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
| 11 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 15 #include "ui/views/widget/native_widget_aura.h" | |
| 16 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 18 | 17 |
| 19 namespace ash { | 18 namespace ash { |
| 20 | 19 |
| 21 // static | 20 // static |
| 22 const char PanelFrameView::kViewClassName[] = "PanelFrameView"; | 21 const char PanelFrameView::kViewClassName[] = "PanelFrameView"; |
| 23 | 22 |
| 24 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) | 23 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) |
| 25 : frame_(frame), | 24 : frame_(frame), |
| 26 caption_button_container_(NULL), | 25 caption_button_container_(NULL), |
| 27 window_icon_(NULL), | 26 window_icon_(NULL), |
| 28 title_font_list_(views::NativeWidgetAura::GetWindowTitleFontList()), | |
| 29 frame_border_hit_test_controller_( | 27 frame_border_hit_test_controller_( |
| 30 new FrameBorderHitTestController(frame_)) { | 28 new FrameBorderHitTestController(frame_)) { |
| 31 DCHECK(!frame_->widget_delegate()->CanMaximize()); | 29 DCHECK(!frame_->widget_delegate()->CanMaximize()); |
| 32 if (frame_type != FRAME_NONE) | 30 if (frame_type != FRAME_NONE) |
| 33 InitHeaderPainter(); | 31 InitHeaderPainter(); |
| 34 } | 32 } |
| 35 | 33 |
| 36 PanelFrameView::~PanelFrameView() { | 34 PanelFrameView::~PanelFrameView() { |
| 37 } | 35 } |
| 38 | 36 |
| 39 const char* PanelFrameView::GetClassName() const { | 37 const char* PanelFrameView::GetClassName() const { |
| 40 return kViewClassName; | 38 return kViewClassName; |
| 41 } | 39 } |
| 42 | 40 |
| 43 void PanelFrameView::InitHeaderPainter() { | 41 void PanelFrameView::InitHeaderPainter() { |
| 44 header_painter_.reset(new HeaderPainter); | 42 header_painter_.reset(new DefaultHeaderPainter); |
| 45 | 43 |
| 46 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, | 44 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, |
| 47 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 45 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 48 AddChildView(caption_button_container_); | 46 AddChildView(caption_button_container_); |
| 49 | 47 |
| 50 if (frame_->widget_delegate()->ShouldShowWindowIcon()) { | 48 if (frame_->widget_delegate()->ShouldShowWindowIcon()) { |
| 51 window_icon_ = new views::ImageView(); | 49 window_icon_ = new views::ImageView(); |
| 52 AddChildView(window_icon_); | 50 AddChildView(window_icon_); |
| 53 } | 51 } |
| 54 | 52 |
| 55 header_painter_->Init(HeaderPainter::STYLE_OTHER, frame_, this, window_icon_, | 53 header_painter_->Init(frame_, this, window_icon_, caption_button_container_); |
| 56 caption_button_container_); | |
| 57 } | 54 } |
| 58 | 55 |
| 59 int PanelFrameView::NonClientTopBorderHeight() const { | 56 int PanelFrameView::NonClientTopBorderHeight() const { |
| 60 if (!header_painter_) | 57 if (!header_painter_) |
| 61 return 0; | 58 return 0; |
| 62 // Reserve enough space to see the buttons and the separator line. | 59 return header_painter_->GetHeaderHeightForPainting(); |
| 63 return caption_button_container_->bounds().bottom() + | |
| 64 header_painter_->HeaderContentSeparatorSize(); | |
| 65 } | 60 } |
| 66 | 61 |
| 67 gfx::Size PanelFrameView::GetMinimumSize() { | 62 gfx::Size PanelFrameView::GetMinimumSize() { |
| 68 if (!header_painter_) | 63 if (!header_painter_) |
| 69 return gfx::Size(); | 64 return gfx::Size(); |
| 70 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize()); | 65 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize()); |
| 71 return gfx::Size( | 66 return gfx::Size( |
| 72 std::max(header_painter_->GetMinimumHeaderWidth(), | 67 std::max(header_painter_->GetMinimumHeaderWidth(), |
| 73 min_client_view_size.width()), | 68 min_client_view_size.width()), |
| 74 NonClientTopBorderHeight() + min_client_view_size.height()); | 69 NonClientTopBorderHeight() + min_client_view_size.height()); |
| 75 } | 70 } |
| 76 | 71 |
| 77 void PanelFrameView::Layout() { | 72 void PanelFrameView::Layout() { |
| 78 if (!header_painter_) | 73 if (!header_painter_) |
| 79 return; | 74 return; |
| 80 header_painter_->LayoutHeader(); | 75 header_painter_->LayoutHeader(); |
| 81 header_painter_->set_header_height(NonClientTopBorderHeight()); | |
| 82 } | 76 } |
| 83 | 77 |
| 84 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { | 78 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { |
| 85 // Nothing. | 79 // Nothing. |
| 86 } | 80 } |
| 87 | 81 |
| 88 void PanelFrameView::ResetWindowControls() { | 82 void PanelFrameView::ResetWindowControls() { |
| 89 NOTIMPLEMENTED(); | 83 NOTIMPLEMENTED(); |
| 90 } | 84 } |
| 91 | 85 |
| 92 void PanelFrameView::UpdateWindowIcon() { | 86 void PanelFrameView::UpdateWindowIcon() { |
| 93 if (!window_icon_) | 87 if (!window_icon_) |
| 94 return; | 88 return; |
| 95 views::WidgetDelegate* delegate = frame_->widget_delegate(); | 89 views::WidgetDelegate* delegate = frame_->widget_delegate(); |
| 96 if (delegate) | 90 if (delegate) |
| 97 window_icon_->SetImage(delegate->GetWindowIcon()); | 91 window_icon_->SetImage(delegate->GetWindowIcon()); |
| 98 window_icon_->SchedulePaint(); | 92 window_icon_->SchedulePaint(); |
| 99 } | 93 } |
| 100 | 94 |
| 101 void PanelFrameView::UpdateWindowTitle() { | 95 void PanelFrameView::UpdateWindowTitle() { |
| 102 if (!header_painter_) | 96 if (!header_painter_) |
| 103 return; | 97 return; |
| 104 header_painter_->SchedulePaintForTitle(title_font_list_); | 98 header_painter_->SchedulePaintForTitle(); |
| 105 } | 99 } |
| 106 | 100 |
| 107 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { | 101 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { |
| 108 if (!header_painter_) | 102 if (!header_painter_) |
| 109 return HTNOWHERE; | 103 return HTNOWHERE; |
| 110 return FrameBorderHitTestController::NonClientHitTest(this, | 104 return FrameBorderHitTestController::NonClientHitTest(this, |
| 111 header_painter_.get(), point); | 105 caption_button_container_, point); |
| 112 } | 106 } |
| 113 | 107 |
| 114 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { | 108 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { |
| 115 if (!header_painter_) | 109 if (!header_painter_) |
| 116 return; | 110 return; |
| 117 bool paint_as_active = ShouldPaintAsActive(); | 111 bool paint_as_active = ShouldPaintAsActive(); |
| 118 caption_button_container_->SetPaintAsActive(paint_as_active); | 112 caption_button_container_->SetPaintAsActive(paint_as_active); |
| 119 | 113 |
| 120 int theme_frame_id = 0; | |
| 121 if (paint_as_active) | |
| 122 theme_frame_id = IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | |
| 123 else | |
| 124 theme_frame_id = IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; | |
| 125 | |
| 126 HeaderPainter::Mode header_mode = paint_as_active ? | 114 HeaderPainter::Mode header_mode = paint_as_active ? |
| 127 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; | 115 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; |
| 128 header_painter_->PaintHeader(canvas, header_mode, theme_frame_id, 0); | 116 header_painter_->PaintHeader(canvas, header_mode); |
| 129 header_painter_->PaintTitleBar(canvas, title_font_list_); | |
| 130 header_painter_->PaintHeaderContentSeparator(canvas, header_mode); | |
| 131 } | 117 } |
| 132 | 118 |
| 133 gfx::Rect PanelFrameView::GetBoundsForClientView() const { | 119 gfx::Rect PanelFrameView::GetBoundsForClientView() const { |
| 134 if (!header_painter_) | 120 gfx::Rect client_bounds = bounds(); |
| 135 return bounds(); | 121 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
| 136 return HeaderPainter::GetBoundsForClientView( | 122 return client_bounds; |
| 137 NonClientTopBorderHeight(), bounds()); | |
| 138 } | 123 } |
| 139 | 124 |
| 140 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( | 125 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( |
| 141 const gfx::Rect& client_bounds) const { | 126 const gfx::Rect& client_bounds) const { |
| 142 if (!header_painter_) | 127 gfx::Rect window_bounds = client_bounds; |
| 143 return client_bounds; | 128 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); |
| 144 return HeaderPainter::GetWindowBoundsForClientBounds( | 129 return window_bounds; |
| 145 NonClientTopBorderHeight(), client_bounds); | |
| 146 } | 130 } |
| 147 | 131 |
| 148 } // namespace ash | 132 } // namespace ash |
| OLD | NEW |