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