Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: ash/wm/panel_frame_view.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback and add unit test for PanelLayoutManager minimize/restore Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 return gfx::Insets(0, 0, frame_painter_->HeaderHeight(), 0);
38 }
39
40 void PanelFrameView::InitFramePainter(views::Widget* frame) {
41 frame_painter_.reset(new FramePainter);
42
27 close_button_ = new views::ImageButton(this); 43 close_button_ = new views::ImageButton(this);
28 close_button_->SetAccessibleName( 44 close_button_->SetAccessibleName(
29 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 45 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
30 AddChildView(close_button_); 46 AddChildView(close_button_);
31 47
32 minimize_button_ = new views::ImageButton(this); 48 minimize_button_ = new views::ImageButton(this);
33 minimize_button_->SetAccessibleName( 49 minimize_button_->SetAccessibleName(
34 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); 50 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE));
35 AddChildView(minimize_button_); 51 AddChildView(minimize_button_);
36 52
37 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, 53 frame_painter_->Init(frame, NULL, minimize_button_, close_button_,
38 FramePainter::SIZE_BUTTON_MINIMIZES); 54 FramePainter::SIZE_BUTTON_MINIMIZES);
39 } 55 }
40 56
41 PanelFrameView::~PanelFrameView() {
42 }
43
44 void PanelFrameView::Layout() { 57 void PanelFrameView::Layout() {
58 if (!frame_painter_.get())
59 return;
45 frame_painter_->LayoutHeader(this, true); 60 frame_painter_->LayoutHeader(this, true);
46 } 61 }
47 62
48 void PanelFrameView::ResetWindowControls() { 63 void PanelFrameView::ResetWindowControls() {
49 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
50 } 65 }
51 66
52 void PanelFrameView::UpdateWindowIcon() { 67 void PanelFrameView::UpdateWindowIcon() {
53 NOTIMPLEMENTED(); 68 NOTIMPLEMENTED();
54 } 69 }
55 70
56 void PanelFrameView::UpdateWindowTitle() { 71 void PanelFrameView::UpdateWindowTitle() {
57 NOTIMPLEMENTED(); 72 // TODO(stevenjb): Support titles for panels?
58 } 73 }
59 74
60 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { 75 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
61 // Nothing. 76 // Nothing.
62 } 77 }
63 78
64 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { 79 int PanelFrameView::NonClientHitTest(const gfx::Point& point) {
80 if (!frame_painter_.get())
81 return HTNOWHERE;
65 return frame_painter_->NonClientHitTest(this, point); 82 return frame_painter_->NonClientHitTest(this, point);
66 } 83 }
67 84
68 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { 85 void PanelFrameView::OnPaint(gfx::Canvas* canvas) {
86 if (!frame_painter_.get())
87 return;
69 bool paint_as_active = ShouldPaintAsActive(); 88 bool paint_as_active = ShouldPaintAsActive();
70 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : 89 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE :
71 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; 90 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;
72 frame_painter_->PaintHeader( 91 frame_painter_->PaintHeader(
73 this, 92 this,
74 canvas, 93 canvas,
75 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, 94 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE,
76 theme_image_id, 95 theme_image_id,
77 NULL); 96 NULL);
78 frame_painter_->PaintHeaderContentSeparator(this, canvas); 97 frame_painter_->PaintHeaderContentSeparator(this, canvas);
79 } 98 }
80 99
81 gfx::Rect PanelFrameView::GetBoundsForClientView() const { 100 gfx::Rect PanelFrameView::GetBoundsForClientView() const {
101 if (!frame_painter_.get())
102 return bounds();
82 return frame_painter_->GetBoundsForClientView( 103 return frame_painter_->GetBoundsForClientView(
83 close_button_->bounds().bottom(), 104 close_button_->bounds().bottom(),
84 bounds()); 105 bounds());
85 } 106 }
86 107
87 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( 108 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds(
88 const gfx::Rect& client_bounds) const { 109 const gfx::Rect& client_bounds) const {
110 if (!frame_painter_.get())
111 return client_bounds;
89 return frame_painter_->GetWindowBoundsForClientBounds( 112 return frame_painter_->GetWindowBoundsForClientBounds(
90 close_button_->bounds().bottom(), client_bounds); 113 close_button_->bounds().bottom(), client_bounds);
91 } 114 }
92 115
93 void PanelFrameView::ButtonPressed(views::Button* sender, 116 void PanelFrameView::ButtonPressed(views::Button* sender,
94 const ui::Event& event) { 117 const ui::Event& event) {
95 if (sender == close_button_) 118 if (sender == close_button_)
96 GetWidget()->Close(); 119 GetWidget()->Close();
120 if (sender == minimize_button_)
121 GetWidget()->Minimize();
97 } 122 }
98 123
99 } // namespace ash 124 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698