| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/wm/panels/panel_frame_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/frame/frame_border_hit_test.h" | |
| 10 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/common/wm_window.h" | |
| 12 #include "ui/aura/client/aura_constants.h" | |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/base/hit_test.h" | |
| 15 #include "ui/gfx/canvas.h" | |
| 16 #include "ui/views/controls/image_view.h" | |
| 17 #include "ui/views/widget/widget.h" | |
| 18 #include "ui/views/widget/widget_delegate.h" | |
| 19 | |
| 20 namespace ash { | |
| 21 | |
| 22 // static | |
| 23 const char PanelFrameView::kViewClassName[] = "PanelFrameView"; | |
| 24 | |
| 25 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) | |
| 26 : frame_(frame), caption_button_container_(nullptr), window_icon_(nullptr) { | |
| 27 GetWidgetWindow()->InstallResizeHandleWindowTargeter(nullptr); | |
| 28 DCHECK(!frame_->widget_delegate()->CanMaximize()); | |
| 29 if (frame_type != FRAME_NONE) | |
| 30 InitHeaderPainter(); | |
| 31 WmShell::Get()->AddShellObserver(this); | |
| 32 } | |
| 33 | |
| 34 PanelFrameView::~PanelFrameView() { | |
| 35 WmShell::Get()->RemoveShellObserver(this); | |
| 36 } | |
| 37 | |
| 38 void PanelFrameView::SetFrameColors(SkColor active_frame_color, | |
| 39 SkColor inactive_frame_color) { | |
| 40 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color); | |
| 41 GetWidgetWindow()->aura_window()->SetProperty( | |
| 42 aura::client::kTopViewColor, header_painter_->GetInactiveFrameColor()); | |
| 43 } | |
| 44 | |
| 45 const char* PanelFrameView::GetClassName() const { | |
| 46 return kViewClassName; | |
| 47 } | |
| 48 | |
| 49 void PanelFrameView::InitHeaderPainter() { | |
| 50 header_painter_.reset(new DefaultHeaderPainter); | |
| 51 GetWidgetWindow()->aura_window()->SetProperty( | |
| 52 aura::client::kTopViewColor, header_painter_->GetInactiveFrameColor()); | |
| 53 | |
| 54 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); | |
| 55 AddChildView(caption_button_container_); | |
| 56 | |
| 57 header_painter_->Init(frame_, this, caption_button_container_); | |
| 58 | |
| 59 if (frame_->widget_delegate()->ShouldShowWindowIcon()) { | |
| 60 window_icon_ = new views::ImageView(); | |
| 61 AddChildView(window_icon_); | |
| 62 header_painter_->UpdateLeftHeaderView(window_icon_); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 WmWindow* PanelFrameView::GetWidgetWindow() { | |
| 67 return WmWindow::Get(frame_->GetNativeWindow()); | |
| 68 } | |
| 69 | |
| 70 int PanelFrameView::NonClientTopBorderHeight() const { | |
| 71 if (!header_painter_) | |
| 72 return 0; | |
| 73 return header_painter_->GetHeaderHeightForPainting(); | |
| 74 } | |
| 75 | |
| 76 gfx::Size PanelFrameView::GetMinimumSize() const { | |
| 77 if (!header_painter_) | |
| 78 return gfx::Size(); | |
| 79 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize()); | |
| 80 return gfx::Size(std::max(header_painter_->GetMinimumHeaderWidth(), | |
| 81 min_client_view_size.width()), | |
| 82 NonClientTopBorderHeight() + min_client_view_size.height()); | |
| 83 } | |
| 84 | |
| 85 void PanelFrameView::Layout() { | |
| 86 if (!header_painter_) | |
| 87 return; | |
| 88 header_painter_->LayoutHeader(); | |
| 89 GetWidgetWindow()->aura_window()->SetProperty(aura::client::kTopViewInset, | |
| 90 NonClientTopBorderHeight()); | |
| 91 } | |
| 92 | |
| 93 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { | |
| 94 // Nothing. | |
| 95 } | |
| 96 | |
| 97 void PanelFrameView::ResetWindowControls() { | |
| 98 NOTIMPLEMENTED(); | |
| 99 } | |
| 100 | |
| 101 void PanelFrameView::UpdateWindowIcon() { | |
| 102 if (!window_icon_) | |
| 103 return; | |
| 104 views::WidgetDelegate* delegate = frame_->widget_delegate(); | |
| 105 if (delegate) | |
| 106 window_icon_->SetImage(delegate->GetWindowIcon()); | |
| 107 window_icon_->SchedulePaint(); | |
| 108 } | |
| 109 | |
| 110 void PanelFrameView::UpdateWindowTitle() { | |
| 111 if (!header_painter_) | |
| 112 return; | |
| 113 header_painter_->SchedulePaintForTitle(); | |
| 114 } | |
| 115 | |
| 116 void PanelFrameView::SizeConstraintsChanged() {} | |
| 117 | |
| 118 gfx::Rect PanelFrameView::GetBoundsForClientView() const { | |
| 119 gfx::Rect client_bounds = bounds(); | |
| 120 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | |
| 121 return client_bounds; | |
| 122 } | |
| 123 | |
| 124 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( | |
| 125 const gfx::Rect& client_bounds) const { | |
| 126 gfx::Rect window_bounds = client_bounds; | |
| 127 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); | |
| 128 return window_bounds; | |
| 129 } | |
| 130 | |
| 131 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { | |
| 132 if (!header_painter_) | |
| 133 return HTNOWHERE; | |
| 134 return FrameBorderNonClientHitTest(this, caption_button_container_, point); | |
| 135 } | |
| 136 | |
| 137 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { | |
| 138 if (!header_painter_) | |
| 139 return; | |
| 140 bool paint_as_active = ShouldPaintAsActive(); | |
| 141 caption_button_container_->SetPaintAsActive(paint_as_active); | |
| 142 | |
| 143 HeaderPainter::Mode header_mode = paint_as_active | |
| 144 ? HeaderPainter::MODE_ACTIVE | |
| 145 : HeaderPainter::MODE_INACTIVE; | |
| 146 header_painter_->PaintHeader(canvas, header_mode); | |
| 147 } | |
| 148 | |
| 149 /////////////////////////////////////////////////////////////////////////////// | |
| 150 // PanelFrameView, ShellObserver overrides: | |
| 151 | |
| 152 void PanelFrameView::OnOverviewModeStarting() { | |
| 153 caption_button_container_->SetVisible(false); | |
| 154 } | |
| 155 | |
| 156 void PanelFrameView::OnOverviewModeEnded() { | |
| 157 caption_button_container_->SetVisible(true); | |
| 158 } | |
| 159 | |
| 160 } // namespace ash | |
| OLD | NEW |