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

Side by Side Diff: Source/core/html/shadow/ClearButtonElement.cpp

Issue 594093002: Fix for mouse capture and release on ClearButtonElement (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 | « Source/core/html/shadow/ClearButtonElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 21 matching lines...) Expand all
32 #include "core/page/EventHandler.h" 32 #include "core/page/EventHandler.h"
33 #include "core/rendering/RenderView.h" 33 #include "core/rendering/RenderView.h"
34 34
35 namespace blink { 35 namespace blink {
36 36
37 using namespace HTMLNames; 37 using namespace HTMLNames;
38 38
39 inline ClearButtonElement::ClearButtonElement(Document& document, ClearButtonOwn er& clearButtonOwner) 39 inline ClearButtonElement::ClearButtonElement(Document& document, ClearButtonOwn er& clearButtonOwner)
40 : HTMLDivElement(document) 40 : HTMLDivElement(document)
41 , m_clearButtonOwner(&clearButtonOwner) 41 , m_clearButtonOwner(&clearButtonOwner)
42 , m_capturing(false)
43 { 42 {
44 } 43 }
45 44
46 PassRefPtrWillBeRawPtr<ClearButtonElement> ClearButtonElement::create(Document& document, ClearButtonOwner& clearButtonOwner) 45 PassRefPtrWillBeRawPtr<ClearButtonElement> ClearButtonElement::create(Document& document, ClearButtonOwner& clearButtonOwner)
47 { 46 {
48 RefPtrWillBeRawPtr<ClearButtonElement> element = adoptRefWillBeNoop(new Clea rButtonElement(document, clearButtonOwner)); 47 RefPtrWillBeRawPtr<ClearButtonElement> element = adoptRefWillBeNoop(new Clea rButtonElement(document, clearButtonOwner));
49 element->setShadowPseudoId(AtomicString("-webkit-clear-button", AtomicString ::ConstructFromLiteral)); 48 element->setShadowPseudoId(AtomicString("-webkit-clear-button", AtomicString ::ConstructFromLiteral));
50 element->setAttribute(idAttr, ShadowElementNames::clearButton()); 49 element->setAttribute(idAttr, ShadowElementNames::clearButton());
51 return element.release(); 50 return element.release();
52 } 51 }
53 52
54 void ClearButtonElement::detach(const AttachContext& context) 53 void ClearButtonElement::detach(const AttachContext& context)
55 { 54 {
56 if (m_capturing) {
57 if (LocalFrame* frame = document().frame())
58 frame->eventHandler().setCapturingMouseEventsNode(nullptr);
59 }
60 HTMLDivElement::detach(context); 55 HTMLDivElement::detach(context);
61 } 56 }
62 57
63 void ClearButtonElement::releaseCapture()
64 {
65 if (!m_capturing)
66 return;
67
68 if (LocalFrame* frame = document().frame()) {
69 frame->eventHandler().setCapturingMouseEventsNode(nullptr);
70 m_capturing = false;
71 }
72 }
73
74 void ClearButtonElement::defaultEventHandler(Event* event) 58 void ClearButtonElement::defaultEventHandler(Event* event)
75 { 59 {
76 if (!m_clearButtonOwner) { 60 if (!m_clearButtonOwner) {
77 if (!event->defaultHandled()) 61 if (!event->defaultHandled())
78 HTMLDivElement::defaultEventHandler(event); 62 HTMLDivElement::defaultEventHandler(event);
79 return; 63 return;
80 } 64 }
81 65
82 if (!m_clearButtonOwner->shouldClearButtonRespondToMouseEvents()) { 66 if (!m_clearButtonOwner->shouldClearButtonRespondToMouseEvents()) {
83 if (!event->defaultHandled()) 67 if (!event->defaultHandled())
84 HTMLDivElement::defaultEventHandler(event); 68 HTMLDivElement::defaultEventHandler(event);
85 return; 69 return;
86 } 70 }
87 71
88 if (event->type() == EventTypeNames::mousedown && event->isMouseEvent() && t oMouseEvent(event)->button() == LeftButton) { 72 if (event->type() == EventTypeNames::click) {
89 if (renderer() && renderer()->visibleToHitTesting()) { 73 if (renderer() && renderer()->visibleToHitTesting()) {
90 if (LocalFrame* frame = document().frame()) { 74 m_clearButtonOwner->focusAndSelectClearButtonOwner();
91 frame->eventHandler().setCapturingMouseEventsNode(this); 75 m_clearButtonOwner->clearValue();
92 m_capturing = true; 76 event->setDefaultHandled();
93 }
94 }
95 m_clearButtonOwner->focusAndSelectClearButtonOwner();
96 event->setDefaultHandled();
97 }
98 if (event->type() == EventTypeNames::mouseup && event->isMouseEvent() && toM ouseEvent(event)->button() == LeftButton) {
99 if (m_capturing) {
100 if (LocalFrame* frame = document().frame()) {
101 frame->eventHandler().setCapturingMouseEventsNode(nullptr);
102 m_capturing = false;
103 }
104 if (hovered()) {
105 m_clearButtonOwner->clearValue();
106 event->setDefaultHandled();
107 }
108 } 77 }
109 } 78 }
110 79
111 if (!event->defaultHandled()) 80 if (!event->defaultHandled())
112 HTMLDivElement::defaultEventHandler(event); 81 HTMLDivElement::defaultEventHandler(event);
113 } 82 }
114 83
115 bool ClearButtonElement::isClearButtonElement() const 84 bool ClearButtonElement::isClearButtonElement() const
116 { 85 {
117 return true; 86 return true;
118 } 87 }
119 88
120 void ClearButtonElement::trace(Visitor* visitor) 89 void ClearButtonElement::trace(Visitor* visitor)
121 { 90 {
122 visitor->trace(m_clearButtonOwner); 91 visitor->trace(m_clearButtonOwner);
123 HTMLDivElement::trace(visitor); 92 HTMLDivElement::trace(visitor);
124 } 93 }
125 94
126 } 95 }
OLDNEW
« no previous file with comments | « Source/core/html/shadow/ClearButtonElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698