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

Side by Side Diff: chrome/browser/chromeos/frame/bubble_frame_view.cc

Issue 8774022: Converting BubbleWindow uses, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Doesn't build... just a checkpoint for this work, might change approach. Created 9 years 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
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/chromeos/frame/bubble_frame_view.h"
6
7 #include <algorithm>
8
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/frame/bubble_window.h"
11 #include "chrome/browser/chromeos/login/helper.h"
12 #include "grit/theme_resources_standard.h"
13 #include "third_party/skia/include/core/SkColor.h"
14 #include "third_party/skia/include/core/SkPaint.h"
15 #include "ui/base/hit_test.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/canvas_skia.h"
18 #include "ui/gfx/font.h"
19 #include "ui/gfx/insets.h"
20 #include "ui/gfx/path.h"
21 #include "ui/gfx/rect.h"
22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/throbber.h"
25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h"
27
28 namespace {
29
30 const int kTitleTopPadding = 10;
31 const int kTitleContentPadding = 10;
32 const int kHorizontalPadding = 10;
33
34 // Title font size correction.
35 #if defined(CROS_FONTS_USING_BCI)
36 const int kTitleFontSizeDelta = 0;
37 #else
38 const int kTitleFontSizeDelta = 1;
39 #endif
40
41 } // namespace
42
43 namespace chromeos {
44
45 BubbleFrameView::BubbleFrameView(views::Widget* frame,
46 views::WidgetDelegate* widget_delegate,
47 DialogStyle style)
48 : frame_(frame),
49 style_(style),
50 title_(NULL),
51 close_button_(NULL),
52 throbber_(NULL) {
53 if (widget_delegate->ShouldShowWindowTitle()) {
54 title_ = new views::Label(widget_delegate->GetWindowTitle());
55 title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
56 title_->SetFont(title_->font().DeriveFont(kFontSizeCorrectionDelta,
57 gfx::Font::BOLD));
58 AddChildView(title_);
59 }
60
61 if (style_ & STYLE_XBAR) {
62 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
63 close_button_ = new views::ImageButton(this);
64 close_button_->SetImage(views::CustomButton::BS_NORMAL,
65 rb.GetBitmapNamed(IDR_CLOSE_BAR));
66 close_button_->SetImage(views::CustomButton::BS_HOT,
67 rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
68 close_button_->SetImage(views::CustomButton::BS_PUSHED,
69 rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
70 AddChildView(close_button_);
71 }
72
73 if (style_ & STYLE_THROBBER) {
74 throbber_ = CreateDefaultSmoothedThrobber();
75 AddChildView(throbber_);
76 }
77 }
78
79 BubbleFrameView::~BubbleFrameView() {
80 }
81
82 void BubbleFrameView::StartThrobber() {
83 DCHECK(throbber_ != NULL);
84 if (title_)
85 title_->SetText(string16());
86 throbber_->Start();
87 }
88
89 void BubbleFrameView::StopThrobber() {
90 DCHECK(throbber_ != NULL);
91 throbber_->Stop();
92 if (title_)
93 title_->SetText(frame_->widget_delegate()->GetWindowTitle());
94 }
95
96 gfx::Rect BubbleFrameView::GetBoundsForClientView() const {
97 return client_view_bounds_;
98 }
99
100 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds(
101 const gfx::Rect& client_bounds) const {
102 gfx::Insets insets = GetInsets();
103
104 gfx::Size title_size;
105 if (title_)
106 title_size = title_->GetPreferredSize();
107 gfx::Size close_button_size;
108 if (close_button_)
109 close_button_size = close_button_->GetPreferredSize();
110 gfx::Size throbber_size;
111 if (throbber_)
112 throbber_size = throbber_->GetPreferredSize();
113
114 int top_height = insets.top();
115 if (title_size.height() > 0 ||
116 close_button_size.height() > 0 ||
117 throbber_size.height() > 0) {
118 top_height += kTitleContentPadding + std::max(
119 std::max(title_size.height(), close_button_size.height()),
120 throbber_size.height());
121 }
122 return gfx::Rect(std::max(0, client_bounds.x() - insets.left()),
123 std::max(0, client_bounds.y() - top_height),
124 client_bounds.width() + insets.width(),
125 client_bounds.height() + top_height + insets.bottom());
126 }
127
128 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) {
129 return HTNOWHERE;
130 }
131
132 void BubbleFrameView::GetWindowMask(const gfx::Size& size,
133 gfx::Path* window_mask) {
134 }
135
136 void BubbleFrameView::ResetWindowControls() {
137 }
138
139 void BubbleFrameView::UpdateWindowIcon() {
140 }
141
142 gfx::Insets BubbleFrameView::GetInsets() const {
143 return (style_ & STYLE_FLUSH || style_ & STYLE_FLUSH_CONTENT) ?
144 gfx::Insets() :
145 gfx::Insets(kTitleTopPadding,
146 kHorizontalPadding,
147 0,
148 kHorizontalPadding);
149 }
150
151 gfx::Size BubbleFrameView::GetPreferredSize() {
152 gfx::Size pref = frame_->client_view()->GetPreferredSize();
153 gfx::Rect bounds(0, 0, pref.width(), pref.height());
154 return frame_->non_client_view()->GetWindowBoundsForClientBounds(
155 bounds).size();
156 }
157
158 void BubbleFrameView::Layout() {
159 gfx::Insets insets = GetInsets();
160
161 gfx::Size title_size;
162 if (title_)
163 title_size = title_->GetPreferredSize();
164 gfx::Size close_button_size;
165 if (close_button_)
166 close_button_size = close_button_->GetPreferredSize();
167 gfx::Size throbber_size;
168 if (throbber_)
169 throbber_size = throbber_->GetPreferredSize();
170
171 // Need to center elements which are shorter.
172 int max_height = std::max(title_size.height(),
173 std::max(close_button_size.height(),
174 throbber_size.height()));
175
176 gfx::Insets title_insets = gfx::Insets();
177 // Need to insert title padding for STYLE_FLUSH_CONTENT.
178 if (style_ & STYLE_FLUSH_CONTENT)
179 title_insets = gfx::Insets(kTitleTopPadding,
180 kHorizontalPadding,
181 0,
182 kHorizontalPadding);
183
184 if (title_) {
185 title_->SetBounds(
186 insets.left() + title_insets.left(),
187 insets.top() + title_insets.top() +
188 (max_height - title_size.height())/2, // Center.
189 std::max(0, width() - insets.width() - title_insets.width() -
190 close_button_size.width()),
191 title_size.height());
192 }
193
194 if (close_button_) {
195 close_button_->SetBounds(
196 width() - insets.right() - title_insets.right() -
197 close_button_size.width(),
198 insets.top() + title_insets.top() +
199 (max_height - close_button_size.height())/2,
200 close_button_size.width(),
201 close_button_size.height());
202 }
203
204 if (throbber_) {
205 throbber_->SetBounds(
206 insets.left() + title_insets.left(),
207 insets.top() + title_insets.top() +
208 (max_height - throbber_size.height())/2,
209 std::min(throbber_size.width(), width()),
210 throbber_size.height());
211 }
212
213 int top_height = insets.top() + title_insets.top();
214 if (title_size.height() > 0 ||
215 close_button_size.height() > 0 ||
216 throbber_size.height() > 0) {
217 top_height += kTitleContentPadding + std::max(
218 std::max(title_size.height(), close_button_size.height()),
219 throbber_size.height());
220 }
221 client_view_bounds_.SetRect(insets.left(), top_height,
222 std::max(0, width() - insets.width()),
223 std::max(0, height() - top_height - insets.bottom()));
224 }
225
226 void BubbleFrameView::OnPaint(gfx::Canvas* canvas) {
227 SkPaint paint;
228 paint.setStyle(SkPaint::kFill_Style);
229 paint.setColor(kBubbleWindowBackgroundColor);
230 gfx::Path path;
231 gfx::Rect bounds(GetContentsBounds());
232 SkRect rect;
233 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()),
234 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom()));
235 path.addRect(rect);
236 canvas->GetSkCanvas()->drawPath(path, paint);
237 }
238
239 void BubbleFrameView::ButtonPressed(views::Button* sender,
240 const views::Event& event) {
241 if (close_button_ != NULL && sender == close_button_)
242 frame_->Close();
243 }
244
245 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/frame/bubble_frame_view.h ('k') | chrome/browser/chromeos/frame/bubble_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698