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

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

Issue 12212207: Support panel titles and Icons for v1 apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment. Created 7 years, 10 months 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
« no previous file with comments | « ash/wm/panel_frame_view.h ('k') | ash/wm/panel_window_event_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 5 #include "ash/wm/panel_frame_view.h"
6 6
7 #include "ash/wm/frame_painter.h" 7 #include "ash/wm/frame_painter.h"
8 #include "grit/ash_resources.h" 8 #include "grit/ash_resources.h"
9 #include "grit/ui_strings.h" // Accessibility names 9 #include "grit/ui_strings.h" // Accessibility names
10 #include "third_party/skia/include/core/SkPaint.h" 10 #include "third_party/skia/include/core/SkPaint.h"
11 #include "ui/base/animation/throb_animation.h" 11 #include "ui/base/animation/throb_animation.h"
12 #include "ui/base/cursor/cursor.h" 12 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/views/controls/button/image_button.h" 19 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/widget/native_widget_aura.h" 20 #include "ui/views/widget/native_widget_aura.h"
21 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h" 22 #include "ui/views/widget/widget_delegate.h"
23 23
24 namespace ash { 24 namespace ash {
25 25
26 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type) { 26 PanelFrameView::PanelFrameView(views::Widget* frame, FrameType frame_type)
27 : frame_(frame),
28 close_button_(NULL),
29 minimize_button_(NULL),
30 window_icon_(NULL),
31 title_font_(gfx::Font(views::NativeWidgetAura::GetWindowTitleFont())) {
27 if (frame_type != FRAME_NONE) 32 if (frame_type != FRAME_NONE)
28 InitFramePainter(frame); 33 InitFramePainter();
29 } 34 }
30 35
31 PanelFrameView::~PanelFrameView() { 36 PanelFrameView::~PanelFrameView() {
32 } 37 }
33 38
34 void PanelFrameView::InitFramePainter(views::Widget* frame) { 39 void PanelFrameView::InitFramePainter() {
35 frame_painter_.reset(new FramePainter); 40 frame_painter_.reset(new FramePainter);
36 41
37 close_button_ = new views::ImageButton(this); 42 close_button_ = new views::ImageButton(this);
38 close_button_->SetAccessibleName( 43 close_button_->SetAccessibleName(
39 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 44 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
40 AddChildView(close_button_); 45 AddChildView(close_button_);
41 46
42 minimize_button_ = new views::ImageButton(this); 47 minimize_button_ = new views::ImageButton(this);
43 minimize_button_->SetAccessibleName( 48 minimize_button_->SetAccessibleName(
44 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); 49 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE));
45 AddChildView(minimize_button_); 50 AddChildView(minimize_button_);
46 51
47 frame_painter_->Init(frame, NULL, minimize_button_, close_button_, 52 if (frame_->widget_delegate()->ShouldShowWindowIcon()) {
53 window_icon_ = new views::ImageButton(this);
54 AddChildView(window_icon_);
55 }
56
57 frame_painter_->Init(frame_, window_icon_, minimize_button_, close_button_,
48 FramePainter::SIZE_BUTTON_MINIMIZES); 58 FramePainter::SIZE_BUTTON_MINIMIZES);
49 } 59 }
50 60
51 void PanelFrameView::Layout() { 61 void PanelFrameView::Layout() {
52 if (!frame_painter_.get()) 62 if (!frame_painter_.get())
53 return; 63 return;
54 frame_painter_->LayoutHeader(this, true); 64 frame_painter_->LayoutHeader(this, true);
55 } 65 }
56 66
57 void PanelFrameView::ResetWindowControls() { 67 void PanelFrameView::ResetWindowControls() {
58 NOTIMPLEMENTED(); 68 NOTIMPLEMENTED();
59 } 69 }
60 70
61 void PanelFrameView::UpdateWindowIcon() { 71 void PanelFrameView::UpdateWindowIcon() {
62 // TODO(stevenjb): Support icons for panels? 72 if (!window_icon_)
73 return;
74 views::WidgetDelegate* delegate = frame_->widget_delegate();
75 if (delegate) {
76 gfx::ImageSkia image = delegate->GetWindowIcon();
77 window_icon_->SetImage(views::CustomButton::STATE_NORMAL, &image);
78 }
79 window_icon_->SchedulePaint();
63 } 80 }
64 81
65 void PanelFrameView::UpdateWindowTitle() { 82 void PanelFrameView::UpdateWindowTitle() {
66 // TODO(stevenjb): Support titles for panels? 83 if (!frame_painter_.get())
84 return;
85 frame_painter_->SchedulePaintForTitle(this, title_font_);
67 } 86 }
68 87
69 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) { 88 void PanelFrameView::GetWindowMask(const gfx::Size&, gfx::Path*) {
70 // Nothing. 89 // Nothing.
71 } 90 }
72 91
73 int PanelFrameView::NonClientHitTest(const gfx::Point& point) { 92 int PanelFrameView::NonClientHitTest(const gfx::Point& point) {
74 if (!frame_painter_.get()) 93 if (!frame_painter_.get())
75 return HTNOWHERE; 94 return HTNOWHERE;
76 return frame_painter_->NonClientHitTest(this, point); 95 return frame_painter_->NonClientHitTest(this, point);
77 } 96 }
78 97
79 void PanelFrameView::OnPaint(gfx::Canvas* canvas) { 98 void PanelFrameView::OnPaint(gfx::Canvas* canvas) {
80 if (!frame_painter_.get()) 99 if (!frame_painter_.get())
81 return; 100 return;
82 bool paint_as_active = ShouldPaintAsActive(); 101 bool paint_as_active = ShouldPaintAsActive();
83 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE : 102 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE :
84 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; 103 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;
85 frame_painter_->PaintHeader( 104 frame_painter_->PaintHeader(
86 this, 105 this,
87 canvas, 106 canvas,
88 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE, 107 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE,
89 theme_image_id, 108 theme_image_id,
90 NULL); 109 NULL);
110 frame_painter_->PaintTitleBar(this, canvas, title_font_);
91 frame_painter_->PaintHeaderContentSeparator(this, canvas); 111 frame_painter_->PaintHeaderContentSeparator(this, canvas);
92 } 112 }
93 113
94 gfx::Rect PanelFrameView::GetBoundsForClientView() const { 114 gfx::Rect PanelFrameView::GetBoundsForClientView() const {
95 if (!frame_painter_.get()) 115 if (!frame_painter_.get())
96 return bounds(); 116 return bounds();
97 return frame_painter_->GetBoundsForClientView( 117 return frame_painter_->GetBoundsForClientView(
98 close_button_->bounds().bottom(), 118 close_button_->bounds().bottom(),
99 bounds()); 119 bounds());
100 } 120 }
101 121
102 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds( 122 gfx::Rect PanelFrameView::GetWindowBoundsForClientBounds(
103 const gfx::Rect& client_bounds) const { 123 const gfx::Rect& client_bounds) const {
104 if (!frame_painter_.get()) 124 if (!frame_painter_.get())
105 return client_bounds; 125 return client_bounds;
106 return frame_painter_->GetWindowBoundsForClientBounds( 126 return frame_painter_->GetWindowBoundsForClientBounds(
107 close_button_->bounds().bottom(), client_bounds); 127 close_button_->bounds().bottom(), client_bounds);
108 } 128 }
109 129
110 void PanelFrameView::ButtonPressed(views::Button* sender, 130 void PanelFrameView::ButtonPressed(views::Button* sender,
111 const ui::Event& event) { 131 const ui::Event& event) {
112 if (sender == close_button_) 132 if (sender == close_button_)
113 GetWidget()->Close(); 133 GetWidget()->Close();
114 if (sender == minimize_button_) 134 if (sender == minimize_button_)
115 GetWidget()->Minimize(); 135 GetWidget()->Minimize();
116 } 136 }
117 137
118 } // namespace ash 138 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panel_frame_view.h ('k') | ash/wm/panel_window_event_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698