| 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/screen.h" | 13 #include "ui/gfx/screen.h" |
| 13 #include "ui/views/bubble/bubble_border.h" | 14 #include "ui/views/bubble/bubble_border.h" |
| 14 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 16 #include "ui/views/window/client_view.h" | 17 #include "ui/views/window/client_view.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Insets, in pixels, for the title view, when it exists. | 21 // Insets, in pixels, for the title view, when it exists. |
| 21 const int kTitleTopInset = 19; | 22 const int kTitleTopInset = 19; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 91 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
| 91 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) | 92 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
| 92 return HTCLOSE; | 93 return HTCLOSE; |
| 93 if (can_drag_ && point.y() < GetInsets().top()) | 94 if (can_drag_ && point.y() < GetInsets().top()) |
| 94 return HTCAPTION; | 95 return HTCAPTION; |
| 95 return GetWidget()->client_view()->NonClientHitTest(point); | 96 return GetWidget()->client_view()->NonClientHitTest(point); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void BubbleFrameView::GetWindowMask(const gfx::Size& size, | 99 void BubbleFrameView::GetWindowMask(const gfx::Size& size, |
| 99 gfx::Path* window_mask) {} | 100 gfx::Path* window_mask) { |
| 101 if (bubble_border_->shadow() != BubbleBorder::NO_SHADOW_OPAQUE_BORDER) |
| 102 return; |
| 103 |
| 104 // Use a window mask roughly matching the border in the image assets. |
| 105 |
| 106 // Stroke size in pixels of borders in image assets. |
| 107 static const int kBorderStrokeSize = 1; |
| 108 |
| 109 gfx::Insets border_insets = bubble_border_->GetInsets(); |
| 110 SkRect rect = {SkIntToScalar(border_insets.left() - kBorderStrokeSize), |
| 111 SkIntToScalar(border_insets.top() - kBorderStrokeSize), |
| 112 SkIntToScalar(size.width() - border_insets.right() + |
| 113 kBorderStrokeSize), |
| 114 SkIntToScalar(size.height() - border_insets.bottom() + |
| 115 kBorderStrokeSize)}; |
| 116 |
| 117 // Approximate rounded corners matching the border. |
| 118 SkPoint polygon[] = { |
| 119 {rect.left() + SkIntToScalar(2), rect.top()}, |
| 120 {rect.left() + SkIntToScalar(1), rect.top() + SkIntToScalar(1)}, |
| 121 {rect.left(), rect.top() + SkIntToScalar(2)}, |
| 122 |
| 123 {rect.left(), rect.bottom() - SkIntToScalar(3)}, |
| 124 {rect.left() + SkIntToScalar(1), rect.bottom() - SkIntToScalar(2)}, |
| 125 {rect.left() + SkIntToScalar(2), rect.bottom()}, |
| 126 |
| 127 {rect.right() - SkIntToScalar(3), rect.bottom()}, |
| 128 {rect.right() - SkIntToScalar(1), rect.bottom() - SkIntToScalar(2)}, |
| 129 {rect.right(), rect.bottom() - SkIntToScalar(3)}, |
| 130 |
| 131 {rect.right(), rect.top() + SkIntToScalar(2)}, |
| 132 {rect.right() - SkIntToScalar(1), rect.top() + SkIntToScalar(1)}, |
| 133 {rect.right() - SkIntToScalar(2), rect.top()} |
| 134 }; |
| 135 |
| 136 window_mask->addPoly(polygon, sizeof(polygon)/sizeof(polygon[0]), true); |
| 137 } |
| 100 | 138 |
| 101 void BubbleFrameView::ResetWindowControls() {} | 139 void BubbleFrameView::ResetWindowControls() {} |
| 102 | 140 |
| 103 void BubbleFrameView::UpdateWindowIcon() {} | 141 void BubbleFrameView::UpdateWindowIcon() {} |
| 104 | 142 |
| 105 void BubbleFrameView::UpdateWindowTitle() {} | 143 void BubbleFrameView::UpdateWindowTitle() {} |
| 106 | 144 |
| 107 gfx::Insets BubbleFrameView::GetInsets() const { | 145 gfx::Insets BubbleFrameView::GetInsets() const { |
| 108 gfx::Insets insets = content_margins_; | 146 gfx::Insets insets = content_margins_; |
| 109 insets += gfx::Insets( | 147 insets += gfx::Insets( |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble | 306 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble |
| 269 // window needs to be moved to the right and that means we need to move arrow | 307 // window needs to be moved to the right and that means we need to move arrow |
| 270 // to the left, and that means negative offset. | 308 // to the left, and that means negative offset. |
| 271 bubble_border_->set_arrow_offset( | 309 bubble_border_->set_arrow_offset( |
| 272 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); | 310 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); |
| 273 if (offscreen_adjust) | 311 if (offscreen_adjust) |
| 274 SchedulePaint(); | 312 SchedulePaint(); |
| 275 } | 313 } |
| 276 | 314 |
| 277 } // namespace views | 315 } // namespace views |
| OLD | NEW |