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/panel_frame_view.h" | |
6 | |
5 #include "ash/wm/frame_painter.h" | 7 #include "ash/wm/frame_painter.h" |
6 #include "ash/wm/panel_frame_view.h" | |
7 #include "grit/ash_resources.h" | 8 #include "grit/ash_resources.h" |
8 #include "grit/ui_strings.h" // Accessibility names | 9 #include "grit/ui_strings.h" // Accessibility names |
9 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
10 #include "ui/base/animation/throb_animation.h" | 11 #include "ui/base/animation/throb_animation.h" |
11 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
12 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
18 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
19 #include "ui/views/widget/native_widget_aura.h" | 20 #include "ui/views/widget/native_widget_aura.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
24 | 25 |
25 PanelFrameView::PanelFrameView(views::Widget* frame) | 26 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) { |
26 : frame_painter_(new FramePainter) { | 27 if (frame_type != FRAME_NONE) |
28 InitFramePainter(frame); | |
29 } | |
30 | |
31 PanelFrameView::~PanelFrameView() { | |
32 } | |
33 | |
34 gfx::Insets PanelFrameView::GetFrameInsets() const { | |
35 if (!frame_painter_.get()) | |
36 return gfx::Insets(); | |
37 int title_height = close_button_->bounds().bottom(); | |
38 return gfx::Insets(0, 0, title_height, 0); | |
sky
2012/11/20 02:05:05
Seems like this should call into FramePainter sinc
stevenjb
2012/11/20 21:20:58
Done.
| |
39 } | |
40 | |
41 void PanelFrameView::InitFramePainter(views::Widget* frame) { | |
42 frame_painter_.reset(new FramePainter); | |
43 | |
27 close_button_ = new views::ImageButton(this); | 44 close_button_ = new views::ImageButton(this); |
28 close_button_->SetAccessibleName( | 45 close_button_->SetAccessibleName( |
29 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 46 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
30 AddChildView(close_button_); | 47 AddChildView(close_button_); |
31 | 48 |
32 minimize_button_ = new views::ImageButton(this); | 49 minimize_button_ = new views::ImageButton(this); |
33 minimize_button_->SetAccessibleName( | 50 minimize_button_->SetAccessibleName( |
34 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 51 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
35 AddChildView(minimize_button_); | 52 AddChildView(minimize_button_); |
36 | 53 |
37 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, | 54 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, |
38 FramePainter::SIZE_BUTTON_MINIMIZES); | 55 FramePainter::SIZE_BUTTON_MINIMIZES); |
39 } | 56 } |
40 | 57 |
41 PanelFrameView::~PanelFrameView() { | |
42 } | |
43 | |
44 void PanelFrameView::Layout() { | 58 void PanelFrameView::Layout() { |
59 if (!frame_painter_.get()) | |
60 return; | |
45 frame_painter_->LayoutHeader(this, true); | 61 frame_painter_->LayoutHeader(this, true); |
46 } | 62 } |
47 | 63 |
48 void PanelFrameView::ResetWindowControls() { | 64 void PanelFrameView::ResetWindowControls() { |
49 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
50 } | 66 } |
51 | 67 |
52 void PanelFrameView::UpdateWindowIcon() { | 68 void PanelFrameView::UpdateWindowIcon() { |
53 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
54 } | 70 } |
55 | 71 |
56 void PanelFrameView::UpdateWindowTitle() { | 72 void PanelFrameView::UpdateWindowTitle() { |
57 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
58 } | 74 } |
59 | 75 |
60 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { | 76 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { |
61 // Nothing. | 77 // Nothing. |
62 } | 78 } |
63 | 79 |
64 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { | 80 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { |
81 if (!frame_painter_.get()) | |
82 return HTNOWHERE; | |
65 return frame_painter_->NonClientHitTest(this, point); | 83 return frame_painter_->NonClientHitTest(this, point); |
66 } | 84 } |
67 | 85 |
68 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { | 86 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { |
87 if (!frame_painter_.get()) | |
88 return; | |
69 bool paint_as_active = ShouldPaintAsActive(); | 89 bool paint_as_active = ShouldPaintAsActive(); |
70 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : | 90 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : |
71 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; | 91 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; |
72 frame_painter_->PaintHeader( | 92 frame_painter_->PaintHeader( |
73 this, | 93 this, |
74 canvas, | 94 canvas, |
75 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, | 95 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, |
76 theme_image_id, | 96 theme_image_id, |
77 NULL); | 97 NULL); |
78 frame_painter_->PaintHeaderContentSeparator(this, canvas); | 98 frame_painter_->PaintHeaderContentSeparator(this, canvas); |
79 } | 99 } |
80 | 100 |
81 gfx::Rect PanelFrameView::GetBoundsForClientView() const { | 101 gfx::Rect PanelFrameView::GetBoundsForClientView() const { |
102 if (!frame_painter_.get()) | |
103 return bounds(); | |
82 return frame_painter_->GetBoundsForClientView( | 104 return frame_painter_->GetBoundsForClientView( |
83 close_button_->bounds().bottom(), | 105 close_button_->bounds().bottom(), |
84 bounds()); | 106 bounds()); |
85 } | 107 } |
86 | 108 |
87 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( | 109 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( |
88 const gfx::Rect& client_bounds) const { | 110 const gfx::Rect& client_bounds) const { |
111 if (!frame_painter_.get()) | |
112 return client_bounds; | |
89 return frame_painter_->GetWindowBoundsForClientBounds( | 113 return frame_painter_->GetWindowBoundsForClientBounds( |
90 close_button_->bounds().bottom(), client_bounds); | 114 close_button_->bounds().bottom(), client_bounds); |
91 } | 115 } |
92 | 116 |
93 void PanelFrameView::ButtonPressed(views::Button* sender, | 117 void PanelFrameView::ButtonPressed(views::Button* sender, |
94 const ui::Event& event) { | 118 const ui::Event& event) { |
95 if (sender == close_button_) | 119 if (sender == close_button_) |
96 GetWidget()->Close(); | 120 GetWidget()->Close(); |
121 if (sender == minimize_button_) | |
122 GetWidget()->Minimize(); | |
97 } | 123 } |
98 | 124 |
99 } // namespace ash | 125 } // namespace ash |
OLD | NEW |