Remove SnowLeopard expected results.
[WebKit-https.git] / Source / WebCore / html / shadow / ClearButtonElement.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ClearButtonElement.h"
28
29 #include "EventHandler.h"
30 #include "Frame.h"
31 #include "MouseEvent.h"
32 #include "RenderView.h"
33
34 namespace WebCore {
35
36 using namespace HTMLNames;
37
38 inline ClearButtonElement::ClearButtonElement(Document* document, ClearButtonOwner& clearButtonOwner)
39     : HTMLDivElement(divTag, document)
40     , m_clearButtonOwner(&clearButtonOwner)
41     , m_capturing(false)
42 {
43     setPseudo(AtomicString("-webkit-clear-button", AtomicString::ConstructFromLiteral));
44 }
45
46 PassRefPtr<ClearButtonElement> ClearButtonElement::create(Document* document, ClearButtonOwner& clearButtonOwner)
47 {
48     return adoptRef(new ClearButtonElement(document, clearButtonOwner));
49 }
50
51 void ClearButtonElement::detach()
52 {
53     if (m_capturing) {
54         if (Frame* frame = document()->frame())
55             frame->eventHandler()->setCapturingMouseEventsNode(0);
56     }
57     HTMLDivElement::detach();
58 }
59
60 void ClearButtonElement::releaseCapture()
61 {
62     if (!m_capturing)
63         return;
64
65     if (Frame* frame = document()->frame()) {
66         frame->eventHandler()->setCapturingMouseEventsNode(0);
67         m_capturing = false;
68     }
69 }
70
71 void ClearButtonElement::defaultEventHandler(Event* event)
72 {
73     if (!m_clearButtonOwner) {
74         if (!event->defaultHandled())
75             HTMLDivElement::defaultEventHandler(event);
76         return;
77     }
78
79     if (!m_clearButtonOwner->shouldClearButtonRespondToMouseEvents()) {
80         if (!event->defaultHandled())
81             HTMLDivElement::defaultEventHandler(event);
82         return;
83     }
84
85     if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
86         if (renderer() && renderer()->visibleToHitTesting()) {
87             if (Frame* frame = document()->frame()) {
88                 frame->eventHandler()->setCapturingMouseEventsNode(this);
89                 m_capturing = true;
90             }
91         }
92         m_clearButtonOwner->focusAndSelectClearButtonOwner();
93         event->setDefaultHandled();
94     }
95     if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
96         if (m_capturing) {
97             if (Frame* frame = document()->frame()) {
98                 frame->eventHandler()->setCapturingMouseEventsNode(0);
99                 m_capturing = false;
100             }
101             if (hovered()) {
102                 m_clearButtonOwner->clearValue();
103                 event->setDefaultHandled();
104             }
105         }
106     }
107
108     if (!event->defaultHandled())
109         HTMLDivElement::defaultEventHandler(event);
110 }
111
112 }