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

Side by Side Diff: ui/views/animation/ink_drop_host_view.cc

Issue 2096003002: Fix crash when InkDropHostView::SetHasInkDrop() is called multiple times (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 4 years, 5 months 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
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_host_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/animation/ink_drop_host_view.h" 5 #include "ui/views/animation/ink_drop_host_view.h"
6 6
7 #include "ui/events/event.h" 7 #include "ui/events/event.h"
8 #include "ui/events/scoped_target_handler.h" 8 #include "ui/events/scoped_target_handler.h"
9 #include "ui/gfx/color_palette.h" 9 #include "ui/gfx/color_palette.h"
10 #include "ui/gfx/geometry/size_conversions.h" 10 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 20 matching lines...) Expand all
31 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); 31 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale);
32 } 32 }
33 33
34 } // namespace 34 } // namespace
35 35
36 // static 36 // static
37 const int InkDropHostView::kInkDropSmallCornerRadius = 2; 37 const int InkDropHostView::kInkDropSmallCornerRadius = 2;
38 38
39 // An EventHandler that is guaranteed to be invoked and is not prone to 39 // An EventHandler that is guaranteed to be invoked and is not prone to
40 // InkDropHostView descendents who do not call 40 // InkDropHostView descendents who do not call
41 // InkDropHostView::OnGestureEvent(). 41 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist
42 // at any given time for each ink drop host view.
42 // 43 //
43 // TODO(bruthig): Consider getting rid of this class. 44 // TODO(bruthig): Consider getting rid of this class.
44 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { 45 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler {
45 public: 46 public:
46 InkDropGestureHandler(InkDropHostView* host_view, InkDrop* ink_drop) 47 InkDropGestureHandler(InkDropHostView* host_view, InkDrop* ink_drop)
47 : target_handler_(new ui::ScopedTargetHandler(host_view, this)), 48 : target_handler_(new ui::ScopedTargetHandler(host_view, this)),
48 host_view_(host_view), 49 host_view_(host_view),
49 ink_drop_(ink_drop) {} 50 ink_drop_(ink_drop) {}
50 51
51 ~InkDropGestureHandler() override {} 52 ~InkDropGestureHandler() override {}
52 53
54 void SetInkDrop(InkDrop* ink_drop) { ink_drop_ = ink_drop; }
55
53 // ui::EventHandler: 56 // ui::EventHandler:
54 void OnGestureEvent(ui::GestureEvent* event) override { 57 void OnGestureEvent(ui::GestureEvent* event) override {
55 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState(); 58 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState();
56 59
57 InkDropState ink_drop_state = InkDropState::HIDDEN; 60 InkDropState ink_drop_state = InkDropState::HIDDEN;
58 switch (event->type()) { 61 switch (event->type()) {
59 case ui::ET_GESTURE_TAP_DOWN: 62 case ui::ET_GESTURE_TAP_DOWN:
60 ink_drop_state = InkDropState::ACTION_PENDING; 63 ink_drop_state = InkDropState::ACTION_PENDING;
61 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so 64 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
62 // that 65 // that
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return gfx::kPlaceholderColor; 219 return gfx::kPlaceholderColor;
217 } 220 }
218 221
219 bool InkDropHostView::ShouldShowInkDropForFocus() const { 222 bool InkDropHostView::ShouldShowInkDropForFocus() const {
220 return false; 223 return false;
221 } 224 }
222 225
223 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) { 226 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) {
224 if (has_an_ink_drop) { 227 if (has_an_ink_drop) {
225 ink_drop_.reset(new InkDropImpl(this)); 228 ink_drop_.reset(new InkDropImpl(this));
226 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get())); 229 if (!gesture_handler_)
230 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get()));
231 else
232 gesture_handler_->SetInkDrop(ink_drop_.get());
227 } else { 233 } else {
228 gesture_handler_.reset(); 234 gesture_handler_.reset();
229 ink_drop_.reset(new InkDropStub()); 235 ink_drop_.reset(new InkDropStub());
230 } 236 }
231 } 237 }
232 238
233 } // namespace views 239 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_host_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698