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 "ui/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ui/base/default_style.h" | 11 #include "ui/base/default_style.h" |
12 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/compositor/paint_context.h" |
| 16 #include "ui/compositor/paint_recorder.h" |
15 #include "ui/gfx/geometry/vector2d.h" | 17 #include "ui/gfx/geometry/vector2d.h" |
16 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
17 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
18 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
19 #include "ui/native_theme/native_theme.h" | 21 #include "ui/native_theme/native_theme.h" |
20 #include "ui/resources/grit/ui_resources.h" | 22 #include "ui/resources/grit/ui_resources.h" |
21 #include "ui/strings/grit/ui_strings.h" | 23 #include "ui/strings/grit/ui_strings.h" |
22 #include "ui/views/bubble/bubble_border.h" | 24 #include "ui/views/bubble/bubble_border.h" |
23 #include "ui/views/controls/button/label_button.h" | 25 #include "ui/views/controls/button/label_button.h" |
24 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 129 } |
128 return client_bounds; | 130 return client_bounds; |
129 } | 131 } |
130 | 132 |
131 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( | 133 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( |
132 const gfx::Rect& client_bounds) const { | 134 const gfx::Rect& client_bounds) const { |
133 gfx::Size size(GetSizeForClientSize(client_bounds.size())); | 135 gfx::Size size(GetSizeForClientSize(client_bounds.size())); |
134 return bubble_border_->GetBounds(gfx::Rect(), size); | 136 return bubble_border_->GetBounds(gfx::Rect(), size); |
135 } | 137 } |
136 | 138 |
| 139 bool BubbleFrameView::GetClientMask(const gfx::Size& size, |
| 140 gfx::Path* path) const { |
| 141 const int radius = bubble_border_->GetBorderCornerRadius(); |
| 142 gfx::RectF rect((gfx::Rect(size))); |
| 143 rect.Inset(gfx::InsetsF(0.5f)); |
| 144 path->addRoundRect(gfx::RectFToSkRect(rect), radius, radius); |
| 145 return true; |
| 146 } |
| 147 |
137 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 148 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
138 if (!bounds().Contains(point)) | 149 if (!bounds().Contains(point)) |
139 return HTNOWHERE; | 150 return HTNOWHERE; |
140 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) | 151 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
141 return HTCLOSE; | 152 return HTCLOSE; |
142 | 153 |
143 // Allow dialogs to show the system menu and be dragged. | 154 // Allow dialogs to show the system menu and be dragged. |
144 if (GetWidget()->widget_delegate()->AsDialogDelegate() && | 155 if (GetWidget()->widget_delegate()->AsDialogDelegate() && |
145 !GetWidget()->widget_delegate()->AsBubbleDialogDelegate()) { | 156 !GetWidget()->widget_delegate()->AsBubbleDialogDelegate()) { |
146 gfx::Rect sys_rect(0, 0, title_->x(), title_->y()); | 157 gfx::Rect sys_rect(0, 0, title_->x(), title_->y()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 title_->SetText(GetWidget()->widget_delegate()->GetWindowTitle()); | 221 title_->SetText(GetWidget()->widget_delegate()->GetWindowTitle()); |
211 title_->SetVisible(GetWidget()->widget_delegate()->ShouldShowWindowTitle()); | 222 title_->SetVisible(GetWidget()->widget_delegate()->ShouldShowWindowTitle()); |
212 } | 223 } |
213 | 224 |
214 void BubbleFrameView::SizeConstraintsChanged() {} | 225 void BubbleFrameView::SizeConstraintsChanged() {} |
215 | 226 |
216 void BubbleFrameView::SetTitleFontList(const gfx::FontList& font_list) { | 227 void BubbleFrameView::SetTitleFontList(const gfx::FontList& font_list) { |
217 title_->SetFontList(font_list); | 228 title_->SetFontList(font_list); |
218 } | 229 } |
219 | 230 |
| 231 const char* BubbleFrameView::GetClassName() const { |
| 232 return kViewClassName; |
| 233 } |
| 234 |
220 gfx::Insets BubbleFrameView::GetInsets() const { | 235 gfx::Insets BubbleFrameView::GetInsets() const { |
221 gfx::Insets insets = content_margins_; | 236 gfx::Insets insets = content_margins_; |
222 | 237 |
223 const int icon_height = title_icon_->GetPreferredSize().height(); | 238 const int icon_height = title_icon_->GetPreferredSize().height(); |
224 const int label_height = title_->GetPreferredSize().height(); | 239 const int label_height = title_->GetPreferredSize().height(); |
225 const bool has_title = icon_height > 0 || label_height > 0; | 240 const bool has_title = icon_height > 0 || label_height > 0; |
226 const int title_padding = has_title ? title_margins_.height() : 0; | 241 const int title_padding = has_title ? title_margins_.height() : 0; |
227 const int title_height = std::max(icon_height, label_height) + title_padding; | 242 const int title_height = std::max(icon_height, label_height) + title_padding; |
228 const int close_height = close_->visible() ? close_->height() : 0; | 243 const int close_height = close_->visible() ? close_->height() : 0; |
229 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); | 244 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 325 |
311 if (footnote_container_) { | 326 if (footnote_container_) { |
312 gfx::Rect local_bounds = GetContentsBounds(); | 327 gfx::Rect local_bounds = GetContentsBounds(); |
313 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); | 328 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); |
314 footnote_container_->SetBounds(local_bounds.x(), | 329 footnote_container_->SetBounds(local_bounds.x(), |
315 local_bounds.bottom() - height, | 330 local_bounds.bottom() - height, |
316 local_bounds.width(), height); | 331 local_bounds.width(), height); |
317 } | 332 } |
318 } | 333 } |
319 | 334 |
320 const char* BubbleFrameView::GetClassName() const { | |
321 return kViewClassName; | |
322 } | |
323 | |
324 void BubbleFrameView::OnThemeChanged() { | 335 void BubbleFrameView::OnThemeChanged() { |
325 UpdateWindowTitle(); | 336 UpdateWindowTitle(); |
326 ResetWindowControls(); | 337 ResetWindowControls(); |
327 UpdateWindowIcon(); | 338 UpdateWindowIcon(); |
328 } | 339 } |
329 | 340 |
330 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 341 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
331 if (bubble_border_ && bubble_border_->use_theme_background_color()) { | 342 if (bubble_border_ && bubble_border_->use_theme_background_color()) { |
332 bubble_border_->set_background_color(GetNativeTheme()-> | 343 bubble_border_->set_background_color(GetNativeTheme()-> |
333 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); | 344 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); |
334 SchedulePaint(); | 345 SchedulePaint(); |
335 } | 346 } |
336 } | 347 } |
337 | 348 |
| 349 void BubbleFrameView::OnPaint(gfx::Canvas* canvas) { |
| 350 OnPaintBackground(canvas); |
| 351 // Border comes after children. |
| 352 } |
| 353 |
| 354 void BubbleFrameView::PaintChildren(const ui::PaintContext& context) { |
| 355 NonClientFrameView::PaintChildren(context); |
| 356 |
| 357 ui::PaintCache paint_cache; |
| 358 ui::PaintRecorder recorder(context, size(), &paint_cache); |
| 359 OnPaintBorder(recorder.canvas()); |
| 360 } |
| 361 |
338 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { | 362 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { |
339 if (sender == close_) { | 363 if (sender == close_) { |
340 close_button_clicked_ = true; | 364 close_button_clicked_ = true; |
341 GetWidget()->Close(); | 365 GetWidget()->Close(); |
342 } | 366 } |
343 } | 367 } |
344 | 368 |
345 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { | 369 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { |
346 bubble_border_ = border.get(); | 370 bubble_border_ = border.get(); |
347 SetBorder(std::move(border)); | 371 SetBorder(std::move(border)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 size.Enlarge(client_insets.width(), client_insets.height()); | 513 size.Enlarge(client_insets.width(), client_insets.height()); |
490 size.SetToMax(gfx::Size(title_bar_width, 0)); | 514 size.SetToMax(gfx::Size(title_bar_width, 0)); |
491 | 515 |
492 if (footnote_container_) | 516 if (footnote_container_) |
493 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 517 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
494 | 518 |
495 return size; | 519 return size; |
496 } | 520 } |
497 | 521 |
498 } // namespace views | 522 } // namespace views |
OLD | NEW |