| 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 | 8 |
| 9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/base/hit_test.h" | 10 #include "ui/base/hit_test.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/path.h" | 12 #include "ui/gfx/path.h" |
| 13 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
| 14 #include "ui/views/bubble/bubble_border.h" | 14 #include "ui/views/bubble/bubble_border.h" |
| 15 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/widget/widget_delegate.h" |
| 17 #include "ui/views/window/client_view.h" | 18 #include "ui/views/window/client_view.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Insets, in pixels, for the title view, when it exists. | 22 // Insets, in pixels, for the title view, when it exists. |
| 22 const int kTitleTopInset = 19; | 23 const int kTitleTopInset = 19; |
| 23 const int kTitleLeftInset = 10; | 24 const int kTitleLeftInset = 10; |
| 24 | 25 |
| 25 // Get the |vertical| or horizontal screen overflow of the |window_bounds|. | 26 // Get the |vertical| or horizontal screen overflow of the |window_bounds|. |
| 26 int GetOffScreenLength(const gfx::Rect& monitor_bounds, | 27 int GetOffScreenLength(const gfx::Rect& monitor_bounds, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 namespace views { | 50 namespace views { |
| 50 | 51 |
| 51 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) | 52 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) |
| 52 : bubble_border_(NULL), | 53 : bubble_border_(NULL), |
| 53 content_margins_(content_margins), | 54 content_margins_(content_margins), |
| 54 title_(NULL), | 55 title_(NULL), |
| 55 close_(NULL), | 56 close_(NULL), |
| 56 titlebar_extra_view_(NULL), | 57 titlebar_extra_view_(NULL) { |
| 57 can_drag_(false) { | |
| 58 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 58 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 59 title_ = new Label(string16(), rb.GetFont(ui::ResourceBundle::MediumFont)); | 59 title_ = new Label(string16(), rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 60 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 60 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 61 AddChildView(title_); | 61 AddChildView(title_); |
| 62 | 62 |
| 63 close_ = new LabelButton(this, string16()); | 63 close_ = new LabelButton(this, string16()); |
| 64 close_->SetImage(CustomButton::STATE_NORMAL, | 64 close_->SetImage(CustomButton::STATE_NORMAL, |
| 65 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | 65 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
| 66 close_->SetImage(CustomButton::STATE_HOVERED, | 66 close_->SetImage(CustomButton::STATE_HOVERED, |
| 67 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); | 67 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 return client_bounds; | 82 return client_bounds; |
| 83 } | 83 } |
| 84 | 84 |
| 85 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( | 85 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( |
| 86 const gfx::Rect& client_bounds) const { | 86 const gfx::Rect& client_bounds) const { |
| 87 return const_cast<BubbleFrameView*>(this)->GetUpdatedWindowBounds( | 87 return const_cast<BubbleFrameView*>(this)->GetUpdatedWindowBounds( |
| 88 gfx::Rect(), client_bounds.size(), false); | 88 gfx::Rect(), client_bounds.size(), false); |
| 89 } | 89 } |
| 90 | 90 |
| 91 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 91 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
| 92 if (!bounds().Contains(point)) |
| 93 return HTNOWHERE; |
| 92 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) | 94 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
| 93 return HTCLOSE; | 95 return HTCLOSE; |
| 94 if (can_drag_ && point.y() < GetInsets().top()) | 96 if (!GetWidget()->widget_delegate()->CanResize()) |
| 97 return GetWidget()->client_view()->NonClientHitTest(point); |
| 98 |
| 99 const int size = bubble_border_->GetBorderThickness() + 4; |
| 100 const int hit = GetHTComponentForFrame(point, size, size, size, size, true); |
| 101 if (hit == HTNOWHERE && point.y() < title_->bounds().bottom()) |
| 95 return HTCAPTION; | 102 return HTCAPTION; |
| 96 return GetWidget()->client_view()->NonClientHitTest(point); | 103 return hit; |
| 97 } | 104 } |
| 98 | 105 |
| 99 void BubbleFrameView::GetWindowMask(const gfx::Size& size, | 106 void BubbleFrameView::GetWindowMask(const gfx::Size& size, |
| 100 gfx::Path* window_mask) { | 107 gfx::Path* window_mask) { |
| 101 if (bubble_border_->shadow() != BubbleBorder::NO_SHADOW_OPAQUE_BORDER) | 108 if (bubble_border_->shadow() != BubbleBorder::NO_SHADOW_OPAQUE_BORDER) |
| 102 return; | 109 return; |
| 103 | 110 |
| 104 // Use a window mask roughly matching the border in the image assets. | 111 // Use a window mask roughly matching the border in the image assets. |
| 105 static const int kBorderStrokeSize = 1; | 112 static const int kBorderStrokeSize = 1; |
| 106 static const SkScalar kCornerRadius = SkIntToScalar(6); | 113 static const SkScalar kCornerRadius = SkIntToScalar(6); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble | 291 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble |
| 285 // window needs to be moved to the right and that means we need to move arrow | 292 // window needs to be moved to the right and that means we need to move arrow |
| 286 // to the left, and that means negative offset. | 293 // to the left, and that means negative offset. |
| 287 bubble_border_->set_arrow_offset( | 294 bubble_border_->set_arrow_offset( |
| 288 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); | 295 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); |
| 289 if (offscreen_adjust) | 296 if (offscreen_adjust) |
| 290 SchedulePaint(); | 297 SchedulePaint(); |
| 291 } | 298 } |
| 292 | 299 |
| 293 } // namespace views | 300 } // namespace views |
| OLD | NEW |