| 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/tray_bubble_view.h" | 5 #include "ui/views/bubble/tray_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 namespace views { | 47 namespace views { |
| 48 | 48 |
| 49 namespace internal { | 49 namespace internal { |
| 50 | 50 |
| 51 // Detects any mouse movement. This is needed to detect mouse movements by the | 51 // Detects any mouse movement. This is needed to detect mouse movements by the |
| 52 // user over the bubble if the bubble got created underneath the cursor. | 52 // user over the bubble if the bubble got created underneath the cursor. |
| 53 class MouseMoveDetectorHost : public MouseWatcherHost { | 53 class MouseMoveDetectorHost : public MouseWatcherHost { |
| 54 public: | 54 public: |
| 55 MouseMoveDetectorHost(); | 55 MouseMoveDetectorHost(); |
| 56 virtual ~MouseMoveDetectorHost(); | 56 ~MouseMoveDetectorHost() override; |
| 57 | 57 |
| 58 virtual bool Contains(const gfx::Point& screen_point, | 58 bool Contains(const gfx::Point& screen_point, MouseEventType type) override; |
| 59 MouseEventType type) override; | 59 |
| 60 private: | 60 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(MouseMoveDetectorHost); | 61 DISALLOW_COPY_AND_ASSIGN(MouseMoveDetectorHost); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 MouseMoveDetectorHost::MouseMoveDetectorHost() { | 64 MouseMoveDetectorHost::MouseMoveDetectorHost() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 MouseMoveDetectorHost::~MouseMoveDetectorHost() { | 67 MouseMoveDetectorHost::~MouseMoveDetectorHost() { |
| 68 } | 68 } |
| 69 | 69 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 82 : BubbleBorder(params.arrow, params.shadow, params.arrow_color), | 82 : BubbleBorder(params.arrow, params.shadow, params.arrow_color), |
| 83 owner_(owner), | 83 owner_(owner), |
| 84 anchor_(anchor), | 84 anchor_(anchor), |
| 85 tray_arrow_offset_(params.arrow_offset), | 85 tray_arrow_offset_(params.arrow_offset), |
| 86 first_item_has_no_margin_(params.first_item_has_no_margin) { | 86 first_item_has_no_margin_(params.first_item_has_no_margin) { |
| 87 set_alignment(params.arrow_alignment); | 87 set_alignment(params.arrow_alignment); |
| 88 set_background_color(params.arrow_color); | 88 set_background_color(params.arrow_color); |
| 89 set_paint_arrow(params.arrow_paint_type); | 89 set_paint_arrow(params.arrow_paint_type); |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual ~TrayBubbleBorder() {} | 92 ~TrayBubbleBorder() override {} |
| 93 | 93 |
| 94 // Overridden from BubbleBorder. | 94 // Overridden from BubbleBorder. |
| 95 // Sets the bubble on top of the anchor when it has no arrow. | 95 // Sets the bubble on top of the anchor when it has no arrow. |
| 96 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 96 gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
| 97 const gfx::Size& contents_size) const override { | 97 const gfx::Size& contents_size) const override { |
| 98 if (has_arrow(arrow())) { | 98 if (has_arrow(arrow())) { |
| 99 gfx::Rect rect = | 99 gfx::Rect rect = |
| 100 BubbleBorder::GetBounds(position_relative_to, contents_size); | 100 BubbleBorder::GetBounds(position_relative_to, contents_size); |
| 101 if (first_item_has_no_margin_) { | 101 if (first_item_has_no_margin_) { |
| 102 if (arrow() == BubbleBorder::BOTTOM_RIGHT || | 102 if (arrow() == BubbleBorder::BOTTOM_RIGHT || |
| 103 arrow() == BubbleBorder::BOTTOM_LEFT) { | 103 arrow() == BubbleBorder::BOTTOM_LEFT) { |
| 104 rect.set_y(rect.y() + kArrowOffsetTopBottom); | 104 rect.set_y(rect.y() + kArrowOffsetTopBottom); |
| 105 int rtl_factor = base::i18n::IsRTL() ? -1 : 1; | 105 int rtl_factor = base::i18n::IsRTL() ? -1 : 1; |
| 106 rect.set_x(rect.x() + | 106 rect.set_x(rect.x() + |
| 107 rtl_factor * kOffsetLeftRightForTopBottomOrientation); | 107 rtl_factor * kOffsetLeftRightForTopBottomOrientation); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder); | 170 DISALLOW_COPY_AND_ASSIGN(TrayBubbleBorder); |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 // This mask layer clips the bubble's content so that it does not overwrite the | 173 // This mask layer clips the bubble's content so that it does not overwrite the |
| 174 // rounded bubble corners. | 174 // rounded bubble corners. |
| 175 // TODO(miket): This does not work on Windows. Implement layer masking or | 175 // TODO(miket): This does not work on Windows. Implement layer masking or |
| 176 // alternate solutions if the TrayBubbleView is needed there in the future. | 176 // alternate solutions if the TrayBubbleView is needed there in the future. |
| 177 class TrayBubbleContentMask : public ui::LayerDelegate { | 177 class TrayBubbleContentMask : public ui::LayerDelegate { |
| 178 public: | 178 public: |
| 179 explicit TrayBubbleContentMask(int corner_radius); | 179 explicit TrayBubbleContentMask(int corner_radius); |
| 180 virtual ~TrayBubbleContentMask(); | 180 ~TrayBubbleContentMask() override; |
| 181 | 181 |
| 182 ui::Layer* layer() { return &layer_; } | 182 ui::Layer* layer() { return &layer_; } |
| 183 | 183 |
| 184 // Overridden from LayerDelegate. | 184 // Overridden from LayerDelegate. |
| 185 virtual void OnPaintLayer(gfx::Canvas* canvas) override; | 185 void OnPaintLayer(gfx::Canvas* canvas) override; |
| 186 virtual void OnDelegatedFrameDamage( | 186 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| 187 const gfx::Rect& damage_rect_in_dip) override {} | 187 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
| 188 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 188 base::Closure PrepareForLayerBoundsChange() override; |
| 189 virtual base::Closure PrepareForLayerBoundsChange() override; | |
| 190 | 189 |
| 191 private: | 190 private: |
| 192 ui::Layer layer_; | 191 ui::Layer layer_; |
| 193 int corner_radius_; | 192 int corner_radius_; |
| 194 | 193 |
| 195 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); | 194 DISALLOW_COPY_AND_ASSIGN(TrayBubbleContentMask); |
| 196 }; | 195 }; |
| 197 | 196 |
| 198 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) | 197 TrayBubbleContentMask::TrayBubbleContentMask(int corner_radius) |
| 199 : layer_(ui::LAYER_TEXTURED), | 198 : layer_(ui::LAYER_TEXTURED), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 224 | 223 |
| 225 // Custom layout for the bubble-view. Does the default box-layout if there is | 224 // Custom layout for the bubble-view. Does the default box-layout if there is |
| 226 // enough height. Otherwise, makes sure the bottom rows are visible. | 225 // enough height. Otherwise, makes sure the bottom rows are visible. |
| 227 class BottomAlignedBoxLayout : public BoxLayout { | 226 class BottomAlignedBoxLayout : public BoxLayout { |
| 228 public: | 227 public: |
| 229 explicit BottomAlignedBoxLayout(TrayBubbleView* bubble_view) | 228 explicit BottomAlignedBoxLayout(TrayBubbleView* bubble_view) |
| 230 : BoxLayout(BoxLayout::kVertical, 0, 0, 0), | 229 : BoxLayout(BoxLayout::kVertical, 0, 0, 0), |
| 231 bubble_view_(bubble_view) { | 230 bubble_view_(bubble_view) { |
| 232 } | 231 } |
| 233 | 232 |
| 234 virtual ~BottomAlignedBoxLayout() {} | 233 ~BottomAlignedBoxLayout() override {} |
| 235 | 234 |
| 236 private: | 235 private: |
| 237 virtual void Layout(View* host) override { | 236 void Layout(View* host) override { |
| 238 if (host->height() >= host->GetPreferredSize().height() || | 237 if (host->height() >= host->GetPreferredSize().height() || |
| 239 !bubble_view_->is_gesture_dragging()) { | 238 !bubble_view_->is_gesture_dragging()) { |
| 240 BoxLayout::Layout(host); | 239 BoxLayout::Layout(host); |
| 241 return; | 240 return; |
| 242 } | 241 } |
| 243 | 242 |
| 244 int consumed_height = 0; | 243 int consumed_height = 0; |
| 245 for (int i = host->child_count() - 1; | 244 for (int i = host->child_count() - 1; |
| 246 i >= 0 && consumed_height < host->height(); --i) { | 245 i >= 0 && consumed_height < host->height(); --i) { |
| 247 View* child = host->child_at(i); | 246 View* child = host->child_at(i); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 void TrayBubbleView::ViewHierarchyChanged( | 498 void TrayBubbleView::ViewHierarchyChanged( |
| 500 const ViewHierarchyChangedDetails& details) { | 499 const ViewHierarchyChangedDetails& details) { |
| 501 if (details.is_add && details.child == this) { | 500 if (details.is_add && details.child == this) { |
| 502 details.parent->SetPaintToLayer(true); | 501 details.parent->SetPaintToLayer(true); |
| 503 details.parent->SetFillsBoundsOpaquely(true); | 502 details.parent->SetFillsBoundsOpaquely(true); |
| 504 details.parent->layer()->SetMasksToBounds(true); | 503 details.parent->layer()->SetMasksToBounds(true); |
| 505 } | 504 } |
| 506 } | 505 } |
| 507 | 506 |
| 508 } // namespace views | 507 } // namespace views |
| OLD | NEW |