Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / wm / panels / panel_frame_view.cc
blob733af9adfbd43e1fb57901a72587359d934b31d3
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.
5 #include "ash/wm/panels/panel_frame_view.h"
7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
8 #include "ash/frame/default_header_painter.h"
9 #include "ash/frame/frame_border_hit_test_controller.h"
10 #include "ui/base/hit_test.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/controls/image_view.h"
13 #include "ui/views/widget/widget.h"
14 #include "ui/views/widget/widget_delegate.h"
16 namespace ash {
18 // static
19 const char PanelFrameView::kViewClassName[] = "PanelFrameView";
21 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type)
22 : frame_(frame),
23 caption_button_container_(NULL),
24 window_icon_(NULL),
25 frame_border_hit_test_controller_(
26 new FrameBorderHitTestController(frame_)) {
27 DCHECK(!frame_->widget_delegate()->CanMaximize());
28 if (frame_type != FRAME_NONE)
29 InitHeaderPainter();
32 PanelFrameView::~PanelFrameView() {
35 const char* PanelFrameView::GetClassName() const {
36 return kViewClassName;
39 void PanelFrameView::InitHeaderPainter() {
40 header_painter_.reset(new DefaultHeaderPainter);
42 caption_button_container_ = new FrameCaptionButtonContainerView(frame_);
43 AddChildView(caption_button_container_);
45 header_painter_->Init(frame_, this, caption_button_container_);
47 if (frame_->widget_delegate()->ShouldShowWindowIcon()) {
48 window_icon_ = new views::ImageView();
49 AddChildView(window_icon_);
50 header_painter_->UpdateLeftHeaderView(window_icon_);
54 int PanelFrameView::NonClientTopBorderHeight() const {
55 if (!header_painter_)
56 return 0;
57 return header_painter_->GetHeaderHeightForPainting();
60 gfx::Size PanelFrameView::GetMinimumSize() const {
61 if (!header_painter_)
62 return gfx::Size();
63 gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize());
64 return gfx::Size(
65 std::max(header_painter_->GetMinimumHeaderWidth(),
66 min_client_view_size.width()),
67 NonClientTopBorderHeight() + min_client_view_size.height());
70 void PanelFrameView::Layout() {
71 if (!header_painter_)
72 return;
73 header_painter_->LayoutHeader();
76 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
77 // Nothing.
80 void PanelFrameView::ResetWindowControls() {
81 NOTIMPLEMENTED();
84 void PanelFrameView::UpdateWindowIcon() {
85 if (!window_icon_)
86 return;
87 views::WidgetDelegate* delegate = frame_->widget_delegate();
88 if (delegate)
89 window_icon_->SetImage(delegate->GetWindowIcon());
90 window_icon_->SchedulePaint();
93 void PanelFrameView::UpdateWindowTitle() {
94 if (!header_painter_)
95 return;
96 header_painter_->SchedulePaintForTitle();
99 void PanelFrameView::SizeConstraintsChanged() {
102 int PanelFrameView::NonClientHitTest(const gfx::Point& point) {
103 if (!header_painter_)
104 return HTNOWHERE;
105 return FrameBorderHitTestController::NonClientHitTest(this,
106 caption_button_container_, point);
109 void PanelFrameView::OnPaint(gfx::Canvas* canvas) {
110 if (!header_painter_)
111 return;
112 bool paint_as_active = ShouldPaintAsActive();
113 caption_button_container_->SetPaintAsActive(paint_as_active);
115 HeaderPainter::Mode header_mode = paint_as_active ?
116 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE;
117 header_painter_->PaintHeader(canvas, header_mode);
120 gfx::Rect PanelFrameView::GetBoundsForClientView() const {
121 gfx::Rect client_bounds = bounds();
122 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
123 return client_bounds;
126 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds(
127 const gfx::Rect& client_bounds) const {
128 gfx::Rect window_bounds = client_bounds;
129 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0);
130 return window_bounds;
133 } // namespace ash