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

Side by Side Diff: Source/modules/accessibility/AXMenuListOption.cpp

Issue 1059503002: Re-land: Don't keep recreating AXMenuListPopup (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@suppress_extra_events
Patch Set: Clean up code Created 5 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2010 Apple 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "modules/accessibility/AXMenuListOption.h" 27 #include "modules/accessibility/AXMenuListOption.h"
28 28
29 #include "core/html/HTMLOptionElement.h" 29 #include "core/html/HTMLOptionElement.h"
je_julie(Not used) 2015/04/06 08:42:50 You can remove "HTMLOptionElement.h" because you a
dmazzoni 2015/04/06 15:42:12 Done.
30 #include "modules/accessibility/AXMenuListPopup.h" 30 #include "modules/accessibility/AXMenuListPopup.h"
31 #include "modules/accessibility/AXObjectCacheImpl.h" 31 #include "modules/accessibility/AXObjectCacheImpl.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 using namespace HTMLNames; 35 using namespace HTMLNames;
36 36
37 AXMenuListOption::AXMenuListOption(AXObjectCacheImpl* axObjectCache) 37 AXMenuListOption::AXMenuListOption(HTMLOptionElement* element, AXObjectCacheImpl * axObjectCache)
38 : AXMockObject(axObjectCache) 38 : AXMockObject(axObjectCache)
39 , m_element(element)
39 { 40 {
40 } 41 }
41 42
42 void AXMenuListOption::setElement(HTMLElement* element) 43 void AXMenuListOption::detach()
43 { 44 {
44 ASSERT_ARG(element, isHTMLOptionElement(element)); 45 m_element = nullptr;
45 m_element = element; 46 AXMockObject::detach();
46 } 47 }
47 48
48 Element* AXMenuListOption::actionElement() const 49 Element* AXMenuListOption::actionElement() const
49 { 50 {
50 return m_element.get(); 51 return m_element;
51 } 52 }
52 53
53 bool AXMenuListOption::isEnabled() const 54 bool AXMenuListOption::isEnabled() const
54 { 55 {
55 // isDisabledFormControl() returns true if the parent <select> element is di sabled, 56 // isDisabledFormControl() returns true if the parent <select> element is di sabled,
56 // which we don't want. 57 // which we don't want.
57 return !toHTMLOptionElement(m_element)->ownElementDisabled(); 58 return !m_element->ownElementDisabled();
58 } 59 }
59 60
60 bool AXMenuListOption::isVisible() const 61 bool AXMenuListOption::isVisible() const
61 { 62 {
62 if (!m_parent) 63 if (!m_parent)
63 return false; 64 return false;
64 65
65 // In a single-option select with the popup collapsed, only the selected 66 // In a single-option select with the popup collapsed, only the selected
66 // item is considered visible. 67 // item is considered visible.
67 return !m_parent->isOffScreen() || isSelected(); 68 return !m_parent->isOffScreen() || isSelected();
68 } 69 }
69 70
70 bool AXMenuListOption::isOffScreen() const 71 bool AXMenuListOption::isOffScreen() const
71 { 72 {
72 // Invisible list options are considered to be offscreen. 73 // Invisible list options are considered to be offscreen.
73 return !isVisible(); 74 return !isVisible();
74 } 75 }
75 76
76 bool AXMenuListOption::isSelected() const 77 bool AXMenuListOption::isSelected() const
77 { 78 {
78 AXMenuListPopup* parent = static_cast<AXMenuListPopup*>(parentObject()); 79 AXMenuListPopup* parent = static_cast<AXMenuListPopup*>(parentObject());
79 if (parent && !parent->isOffScreen()) 80 if (parent && !parent->isOffScreen())
80 return parent->activeChild() == this; 81 return parent->activeChild() == this;
81 return toHTMLOptionElement(m_element)->selected(); 82 return m_element->selected();
82 } 83 }
83 84
84 void AXMenuListOption::setSelected(bool b) 85 void AXMenuListOption::setSelected(bool b)
85 { 86 {
86 if (!canSetSelectedAttribute()) 87 if (!canSetSelectedAttribute())
87 return; 88 return;
88 89
89 toHTMLOptionElement(m_element)->setSelected(b); 90 m_element->setSelected(b);
90 } 91 }
91 92
92 bool AXMenuListOption::canSetSelectedAttribute() const 93 bool AXMenuListOption::canSetSelectedAttribute() const
93 { 94 {
94 return isEnabled(); 95 return isEnabled();
95 } 96 }
96 97
97 bool AXMenuListOption::computeAccessibilityIsIgnored() const 98 bool AXMenuListOption::computeAccessibilityIsIgnored() const
98 { 99 {
99 return accessibilityIsIgnoredByDefault(); 100 return accessibilityIsIgnoredByDefault();
100 } 101 }
101 102
102 LayoutRect AXMenuListOption::elementRect() const 103 LayoutRect AXMenuListOption::elementRect() const
103 { 104 {
104 AXObject* parent = parentObject(); 105 AXObject* parent = parentObject();
105 ASSERT(parent->isMenuListPopup()); 106 ASSERT(parent->isMenuListPopup());
106 107
107 AXObject* grandparent = parent->parentObject(); 108 AXObject* grandparent = parent->parentObject();
108 ASSERT(grandparent->isMenuList()); 109 ASSERT(grandparent->isMenuList());
109 110
110 return grandparent->elementRect(); 111 return grandparent->elementRect();
111 } 112 }
112 113
113 String AXMenuListOption::stringValue() const 114 String AXMenuListOption::stringValue() const
114 { 115 {
115 return toHTMLOptionElement(m_element)->text(); 116 return m_element->text();
116 } 117 }
117 118
118 } // namespace blink 119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698