Commit 5f93b7ae authored by Rob Dodson's avatar Rob Dodson Committed by Commit Bot

Replace was_focused_by_mouse_ flag.

Removes the was_focused_by_mouse_ flag implemented by a number of form elements,
and replaces it with a check for Node::WasFocusedByMouse().

R=tkent@chromium.org

Bug: 817199
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ibd8477732d5646f928c010a5c1cef853bafc38ee
Reviewed-on: https://chromium-review.googlesource.com/988352
Commit-Queue: Rob Dodson <robdodson@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548223}
parent 821174db
......@@ -51,7 +51,6 @@ HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tag_name,
Document& document)
: HTMLElement(tag_name, document),
link_relations_(0),
was_focused_by_mouse_(false),
cached_visited_link_hash_(0),
rel_list_(RelList::Create(this)) {}
......@@ -74,27 +73,7 @@ bool HTMLAnchorElement::MatchesEnabledPseudoClass() const {
}
bool HTMLAnchorElement::ShouldHaveFocusAppearance() const {
return !was_focused_by_mouse_ || HTMLElement::SupportsFocus();
}
void HTMLAnchorElement::DispatchFocusEvent(
Element* old_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = type == kWebFocusTypeMouse;
HTMLElement::DispatchFocusEvent(old_focused_element, type,
source_capabilities);
}
void HTMLAnchorElement::DispatchBlurEvent(
Element* new_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = false;
HTMLElement::DispatchBlurEvent(new_focused_element, type,
source_capabilities);
return !WasFocusedByMouse() || HTMLElement::SupportsFocus();
}
bool HTMLAnchorElement::IsMouseFocusable() const {
......
......@@ -105,13 +105,6 @@ class CORE_EXPORT HTMLAnchorElement : public HTMLElement, public DOMURLUtils {
private:
void AttributeChanged(const AttributeModificationParams&) override;
bool ShouldHaveFocusAppearance() const final;
void DispatchFocusEvent(
Element* old_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
void DispatchBlurEvent(Element* new_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
bool IsMouseFocusable() const override;
bool IsKeyboardFocusable() const override;
void DefaultEventHandler(Event*) final;
......@@ -128,7 +121,6 @@ class CORE_EXPORT HTMLAnchorElement : public HTMLElement, public DOMURLUtils {
void HandleClick(Event*);
unsigned link_relations_ : 31;
unsigned was_focused_by_mouse_ : 1;
mutable LinkHash cached_visited_link_hash_;
TraceWrapperMember<RelList> rel_list_;
};
......
......@@ -61,7 +61,6 @@ HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tag_name,
will_validate_(true),
is_valid_(true),
validity_is_dirty_(false),
was_focused_by_mouse_(false),
blocks_form_submission_(false) {
SetHasCustomStyleCallbacks();
}
......@@ -409,33 +408,21 @@ bool HTMLFormControlElement::ShouldShowFocusRingOnMouseFocus() const {
}
bool HTMLFormControlElement::ShouldHaveFocusAppearance() const {
return !was_focused_by_mouse_ || ShouldShowFocusRingOnMouseFocus();
}
void HTMLFormControlElement::DispatchFocusEvent(
Element* old_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = type == kWebFocusTypeMouse;
// ContainerNode::handleStyleChangeOnFocusStateChange() will inform
// LayoutTheme about the focus state change.
HTMLElement::DispatchFocusEvent(old_focused_element, type,
source_capabilities);
return !WasFocusedByMouse() || ShouldShowFocusRingOnMouseFocus();
}
void HTMLFormControlElement::WillCallDefaultEventHandler(const Event& event) {
if (!was_focused_by_mouse_)
if (!WasFocusedByMouse())
return;
if (!event.IsKeyboardEvent() || event.type() != EventTypeNames::keydown)
return;
bool old_should_have_focus_appearance = ShouldHaveFocusAppearance();
was_focused_by_mouse_ = false;
SetWasFocusedByMouse(false);
// Change of m_wasFocusByMouse may affect shouldHaveFocusAppearance() and
// LayoutTheme::isFocused(). Inform LayoutTheme if
// shouldHaveFocusAppearance() changes.
// Changes to WasFocusedByMouse may affect ShouldHaveFocusAppearance() and
// LayoutTheme::IsFocused(). Inform LayoutTheme if
// ShouldHaveFocusAppearance() changes.
if (old_should_have_focus_appearance != ShouldHaveFocusAppearance() &&
GetLayoutObject()) {
GetLayoutObject()->InvalidateIfControlStateChanged(kFocusControlState);
......@@ -654,8 +641,6 @@ void HTMLFormControlElement::DispatchBlurEvent(
Element* new_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = false;
HTMLElement::DispatchBlurEvent(new_focused_element, type,
source_capabilities);
HideVisibleValidationMessage();
......
......@@ -162,10 +162,6 @@ class CORE_EXPORT HTMLFormControlElement : public LabelableElement,
void DispatchBlurEvent(Element* new_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
void DispatchFocusEvent(
Element* old_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
void WillCallDefaultEventHandler(const Event&) final;
void DidRecalcStyle(StyleRecalcChange) override;
......@@ -216,7 +212,6 @@ class CORE_EXPORT HTMLFormControlElement : public LabelableElement,
bool is_valid_ : 1;
bool validity_is_dirty_ : 1;
bool was_focused_by_mouse_ : 1;
bool blocks_form_submission_ : 1;
};
......
......@@ -52,8 +52,7 @@ using namespace HTMLNames;
inline SVGAElement::SVGAElement(Document& document)
: SVGGraphicsElement(SVGNames::aTag, document),
SVGURIReference(this),
svg_target_(SVGAnimatedString::Create(this, SVGNames::targetAttr)),
was_focused_by_mouse_(false) {
svg_target_(SVGAnimatedString::Create(this, SVGNames::targetAttr)) {
AddToPropertyMap(svg_target_);
}
......@@ -164,29 +163,7 @@ bool SVGAElement::SupportsFocus() const {
}
bool SVGAElement::ShouldHaveFocusAppearance() const {
return !was_focused_by_mouse_ || SVGGraphicsElement::SupportsFocus();
}
// TODO(lanwei): Will add the InputDeviceCapabilities when SVGAElement gets
// focus later, see https://crbug.com/476530.
void SVGAElement::DispatchFocusEvent(
Element* old_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = type == kWebFocusTypeMouse;
SVGGraphicsElement::DispatchFocusEvent(old_focused_element, type,
source_capabilities);
}
void SVGAElement::DispatchBlurEvent(
Element* new_focused_element,
WebFocusType type,
InputDeviceCapabilities* source_capabilities) {
if (type != kWebFocusTypePage)
was_focused_by_mouse_ = false;
SVGGraphicsElement::DispatchBlurEvent(new_focused_element, type,
source_capabilities);
return !WasFocusedByMouse() || SVGGraphicsElement::SupportsFocus();
}
bool SVGAElement::IsURLAttribute(const Attribute& attribute) const {
......
......@@ -55,13 +55,6 @@ class CORE_EXPORT SVGAElement final : public SVGGraphicsElement,
bool SupportsFocus() const override;
bool ShouldHaveFocusAppearance() const final;
void DispatchFocusEvent(
Element* old_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
void DispatchBlurEvent(Element* new_focused_element,
WebFocusType,
InputDeviceCapabilities* source_capabilities) override;
bool IsMouseFocusable() const override;
bool IsKeyboardFocusable() const override;
bool IsURLAttribute(const Attribute&) const override;
......@@ -71,7 +64,6 @@ class CORE_EXPORT SVGAElement final : public SVGGraphicsElement,
bool WillRespondToMouseClickEvents() override;
Member<SVGAnimatedString> svg_target_;
bool was_focused_by_mouse_;
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment