Commit cf32375a authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move should_draw_caps_lock_indicator_ flag

from LayoutTextControlSingleLine to PasswordInputType.

LayoutObject should not store such a UI state. This CL will help
LayoutNG transition.

* Moves the followings from LayoutTextControlSingleLine to
  PasswordInputType:
  - should_draw_caps_lock_indicator_ flag
  - CapsLockStateMayHaveChanged()
  - ShouldDrawCapsLockIndicator()

* Moves CapsLockStateMayHaveChanged() calsites in TextFieldInputType to
  PasswordInputType.
  Make TextFieldInputType::ForwardEvent() protected for this.

This CL has no behavior changes.

Bug: 1040826
Change-Id: I47df60b4e38184ad81b75a52ce8835e9af4ed3ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437077
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811648}
parent eef2120b
......@@ -1966,6 +1966,14 @@ bool HTMLInputElement::SupportsInputModeAttribute() const {
return input_type_->SupportsInputModeAttribute();
}
void HTMLInputElement::CapsLockStateMayHaveChanged() {
input_type_view_->CapsLockStateMayHaveChanged();
}
bool HTMLInputElement::ShouldDrawCapsLockIndicator() const {
return input_type_view_->ShouldDrawCapsLockIndicator();
}
void HTMLInputElement::SetShouldRevealPassword(bool value) {
if (!!should_reveal_password_ == value)
return;
......
......@@ -316,6 +316,8 @@ class CORE_EXPORT HTMLInputElement
bool SupportsInputModeAttribute() const;
void CapsLockStateMayHaveChanged();
bool ShouldDrawCapsLockIndicator() const;
void SetShouldRevealPassword(bool value);
bool ShouldRevealPassword() const { return should_reveal_password_; }
AXObject* PopupRootAXObject();
......
......@@ -180,6 +180,12 @@ void InputTypeView::SubtreeHasChanged() {
void InputTypeView::ListAttributeTargetChanged() {}
void InputTypeView::CapsLockStateMayHaveChanged() {}
bool InputTypeView::ShouldDrawCapsLockIndicator() const {
return false;
}
void InputTypeView::UpdateClearButtonVisibility() {}
void InputTypeView::UpdatePlaceholderText() {}
......
......@@ -132,6 +132,8 @@ class CORE_EXPORT InputTypeView : public GarbageCollectedMixin {
virtual void ValueAttributeChanged();
virtual void DidSetValue(const String&, bool value_changed);
virtual void ListAttributeTargetChanged();
virtual void CapsLockStateMayHaveChanged();
virtual bool ShouldDrawCapsLockIndicator() const;
virtual void UpdateClearButtonVisibility();
virtual void UpdatePlaceholderText();
virtual AXObject* PopupRootAXObject();
......
......@@ -43,6 +43,7 @@
#include "third_party/blink/renderer/core/html/forms/form_controller.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/input/keyboard_event_manager.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_text_control_single_line.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
......@@ -126,6 +127,30 @@ void PasswordInputType::UpdateView() {
UpdatePasswordRevealButton();
}
void PasswordInputType::CapsLockStateMayHaveChanged() {
auto& document = GetElement().GetDocument();
LocalFrame* frame = document.GetFrame();
// Only draw the caps lock indicator if these things are true:
// 1) The field is a password field
// 2) The frame is active
// 3) The element is focused
// 4) The caps lock is on
const bool should_draw_caps_lock_indicator =
frame && frame->Selection().FrameIsFocusedAndActive() &&
document.FocusedElement() == GetElement() &&
KeyboardEventManager::CurrentCapsLockState();
if (should_draw_caps_lock_indicator != should_draw_caps_lock_indicator_) {
should_draw_caps_lock_indicator_ = should_draw_caps_lock_indicator;
if (auto* layout_object = GetElement().GetLayoutObject())
layout_object->SetShouldDoFullPaintInvalidation();
}
}
bool PasswordInputType::ShouldDrawCapsLockIndicator() const {
return should_draw_caps_lock_indicator_;
}
void PasswordInputType::UpdatePasswordRevealButton() {
Element* button = GetElement().UserAgentShadowRoot()->getElementById(
shadow_element_names::kIdPasswordRevealButton);
......@@ -163,6 +188,16 @@ void PasswordInputType::UpdatePasswordRevealButton() {
}
}
void PasswordInputType::ForwardEvent(Event& event) {
BaseTextInputType::ForwardEvent(event);
if (GetElement().GetLayoutObject() &&
!GetElement().GetForceReattachLayoutTree() &&
(event.type() == event_type_names::kBlur ||
event.type() == event_type_names::kFocus))
CapsLockStateMayHaveChanged();
}
void PasswordInputType::HandleBlurEvent() {
if (RuntimeEnabledFeatures::PasswordRevealEnabled()) {
should_show_reveal_button_ = false;
......
......@@ -54,16 +54,20 @@ class PasswordInputType final : public BaseTextInputType {
void CreateShadowSubtree() override;
void UpdateView() override;
void CapsLockStateMayHaveChanged() override;
bool ShouldDrawCapsLockIndicator() const override;
void UpdatePasswordRevealButton();
void DidSetValueByUserEdit() override;
void DidSetValue(const String&, bool value_changed) override;
void ForwardEvent(Event& event) override;
void HandleKeydownEvent(KeyboardEvent&) override;
void HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent&) override;
void HandleBlurEvent() override;
bool SupportsInputModeAttribute() const override;
bool should_draw_caps_lock_indicator_ = false;
bool should_show_reveal_button_ = false;
};
......
......@@ -239,8 +239,6 @@ void TextFieldInputType::ForwardEvent(Event& event) {
event.HasInterface(event_interface_names::kWheelEvent) ||
event.type() == event_type_names::kBlur ||
event.type() == event_type_names::kFocus)) {
auto* layout_text_control =
To<LayoutTextControlSingleLine>(GetElement().GetLayoutObject());
if (event.type() == event_type_names::kBlur) {
if (LayoutBox* inner_editor_layout_object =
GetElement().InnerEditorElement()->GetLayoutBox()) {
......@@ -253,10 +251,6 @@ void TextFieldInputType::ForwardEvent(Event& event) {
}
}
}
layout_text_control->CapsLockStateMayHaveChanged();
} else if (event.type() == event_type_names::kFocus) {
layout_text_control->CapsLockStateMayHaveChanged();
}
GetElement().ForwardEvent(event);
......
......@@ -58,6 +58,7 @@ class TextFieldInputType : public InputType,
void DisabledAttributeChanged() override;
void ReadonlyAttributeChanged() override;
bool SupportsReadOnly() const override;
void ForwardEvent(Event&) override;
void HandleBlurEvent() override;
void HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent&) override;
String SanitizeValue(const String&) const override;
......@@ -84,7 +85,6 @@ class TextFieldInputType : public InputType,
bool MayTriggerVirtualKeyboard() const final;
bool IsTextField() const final;
bool ValueMissing(const String&) const override;
void ForwardEvent(Event&) final;
bool ShouldSubmitImplicitly(const Event&) final;
bool ShouldRespectListAttribute() override;
void ListAttributeTargetChanged() override;
......
......@@ -18,13 +18,12 @@
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input/event_handling_util.h"
#include "third_party/blink/renderer/core/input/input_device_capabilities.h"
#include "third_party/blink/renderer/core/input/scroll_manager.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_text_control_single_line.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"
......@@ -348,10 +347,8 @@ WebInputEventResult KeyboardEventManager::KeyEvent(
void KeyboardEventManager::CapsLockStateMayHaveChanged() {
if (Element* element = frame_->GetDocument()->FocusedElement()) {
if (LayoutObject* r = element->GetLayoutObject()) {
if (auto* text_control = DynamicTo<LayoutTextControlSingleLine>(r))
text_control->CapsLockStateMayHaveChanged();
}
if (auto* text_control = DynamicTo<HTMLInputElement>(element))
text_control->CapsLockStateMayHaveChanged();
}
}
......
......@@ -26,15 +26,10 @@
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/input/keyboard_event_manager.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_analyzer.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/platform/fonts/simple_font_data.h"
......@@ -42,7 +37,7 @@ namespace blink {
LayoutTextControlSingleLine::LayoutTextControlSingleLine(
HTMLInputElement* element)
: LayoutTextControl(element), should_draw_caps_lock_indicator_(false) {}
: LayoutTextControl(element) {}
LayoutTextControlSingleLine::~LayoutTextControlSingleLine() = default;
......@@ -179,31 +174,6 @@ bool LayoutTextControlSingleLine::NodeAtPoint(
return true;
}
void LayoutTextControlSingleLine::CapsLockStateMayHaveChanged() {
NOT_DESTROYED();
if (!GetNode())
return;
// Only draw the caps lock indicator if these things are true:
// 1) The field is a password field
// 2) The frame is active
// 3) The element is focused
// 4) The caps lock is on
bool should_draw_caps_lock_indicator = false;
if (LocalFrame* frame = GetDocument().GetFrame())
should_draw_caps_lock_indicator =
InputElement()->type() == input_type_names::kPassword &&
frame->Selection().FrameIsFocusedAndActive() &&
GetDocument().FocusedElement() == GetNode() &&
KeyboardEventManager::CurrentCapsLockState();
if (should_draw_caps_lock_indicator != should_draw_caps_lock_indicator_) {
should_draw_caps_lock_indicator_ = should_draw_caps_lock_indicator;
SetShouldDoFullPaintInvalidation();
}
}
LayoutUnit LayoutTextControlSingleLine::PreferredContentLogicalWidth(
float char_width) const {
NOT_DESTROYED();
......
......@@ -42,12 +42,6 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
LayoutTextControlSingleLine(HTMLInputElement*);
~LayoutTextControlSingleLine() override;
void CapsLockStateMayHaveChanged();
bool ShouldDrawCapsLockIndicator() const {
NOT_DESTROYED();
return should_draw_caps_lock_indicator_;
}
protected:
Element* ContainerElement() const;
Element* EditingViewPortElement() const;
......@@ -90,8 +84,6 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
}
HTMLElement* InnerSpinButtonElement() const;
bool should_draw_caps_lock_indicator_;
};
template <>
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/layout/layout_text_control_single_line.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/block_painter.h"
......@@ -18,7 +19,8 @@ void TextControlSingleLinePainter::Paint(const PaintInfo& paint_info) {
BlockPainter(text_control_).Paint(paint_info);
if (!ShouldPaintSelfBlockBackground(paint_info.phase) ||
!text_control_.ShouldDrawCapsLockIndicator())
!To<HTMLInputElement>(text_control_.GetNode())
->ShouldDrawCapsLockIndicator())
return;
if (DrawingRecorder::UseCachedDrawingIfPossible(
......
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