chromium/third_party/blink/renderer/core/editing/ime/input_method_controller.cc

/*
 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/editing/ime/input_method_controller.h"

#include <tuple>

#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/events/event_dispatcher.h"
#include "third_party/blink/renderer/core/dom/events/scoped_event_queue.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/range.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/commands/delete_selection_command.h"
#include "third_party/blink/renderer/core/editing/commands/undo_stack.h"
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/ime/edit_context.h"
#include "third_party/blink/renderer/core/editing/markers/document_marker_controller.h"
#include "third_party/blink/renderer/core/editing/markers/suggestion_marker_properties.h"
#include "third_party/blink/renderer/core/editing/reveal_selection_scope.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/set_selection_options.h"
#include "third_party/blink/renderer/core/editing/spellcheck/spell_checker.h"
#include "third_party/blink/renderer/core/editing/state_machines/backward_code_point_state_machine.h"
#include "third_party/blink/renderer/core/editing/state_machines/forward_code_point_state_machine.h"
#include "third_party/blink/renderer/core/events/composition_event.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_text_area_element.h"
#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/keywords.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
#include "third_party/blink/renderer/core/page/page.h"

namespace blink {

FormControlType;

namespace {

bool NeedsIncrementalInsertion(const LocalFrame& frame,
                               const String& new_text) {}

AtomicString GetInputModeAttribute(Element* element) {}

AtomicString GetEnterKeyHintAttribute(Element* element) {}

AtomicString GetVirtualKeyboardPolicyAttribute(Element* element) {}

constexpr int kInvalidDeletionLength =;
constexpr bool IsInvalidDeletionLength(const int length) {}

int CalculateBeforeDeletionLengthsInCodePoints(
    const String& text,
    const int before_length_in_code_points,
    const int selection_start) {}

int CalculateAfterDeletionLengthsInCodePoints(
    const String& text,
    const int after_length_in_code_points,
    const int selection_end) {}

Element* RootEditableElementOfSelection(const FrameSelection& frameSelection) {}

std::pair<ContainerNode*, PlainTextRange> PlainTextRangeForEphemeralRange(
    const EphemeralRange& range) {}

int ComputeAutocapitalizeFlags(const Element* element) {}

SuggestionMarker::SuggestionType ConvertImeTextSpanType(
    ImeTextSpan::Type type) {}

ImeTextSpan::Type ConvertSuggestionMarkerType(
    SuggestionMarker::SuggestionType type) {}

// ImeTextSpans types that need to be provided to TextInputInfo can be added
// here.
bool ShouldGetImeTextSpans(ImeTextSpan::Type type) {}

}  // anonymous namespace

enum class InputMethodController::TypingContinuation {};

InputMethodController::InputMethodController(LocalDOMWindow& window,
                                             LocalFrame& frame)
    :{}

InputMethodController::~InputMethodController() = default;

bool InputMethodController::IsAvailable() const {}

Document& InputMethodController::GetDocument() const {}

bool InputMethodController::HasComposition() const {}

inline Editor& InputMethodController::GetEditor() const {}

LocalFrame& InputMethodController::GetFrame() const {}

void InputMethodController::DispatchCompositionUpdateEvent(LocalFrame& frame,
                                                           const String& text) {}

void InputMethodController::DispatchCompositionEndEvent(LocalFrame& frame,
                                                        const String& text) {}

void InputMethodController::DispatchBeforeInputFromComposition(
    EventTarget* target,
    InputEvent::InputType input_type,
    const String& data) {}

// Used to insert/replace text during composition update and confirm
// composition.
// Procedure:
//   1. Fire 'beforeinput' event for (TODO(editing-dev): deleted composed text)
//      and inserted text
//   2. Fire 'compositionupdate' event
//   3. Fire TextEvent and modify DOM
//   4. Fire 'input' event; dispatched by Editor::AppliedEditing()
void InputMethodController::InsertTextDuringCompositionWithEvents(
    LocalFrame& frame,
    const String& text,
    TypingCommand::Options options,
    TypingCommand::TextCompositionType composition_type) {}

void InputMethodController::Clear() {}

void InputMethodController::ClearImeTextSpansByType(ImeTextSpan::Type type,
                                                    unsigned text_start,
                                                    unsigned text_end) {}

void InputMethodController::ContextDestroyed() {}

void InputMethodController::SelectComposition() const {}

bool IsTextTooLongAt(const Position& position) {}

bool InputMethodController::FinishComposingText(
    ConfirmCompositionBehavior confirm_behavior) {}

bool InputMethodController::CommitText(
    const String& text,
    const Vector<ImeTextSpan>& ime_text_spans,
    int relative_caret_position) {}

bool InputMethodController::ReplaceTextAndMoveCaret(
    const String& text,
    PlainTextRange range,
    MoveCaretBehavior move_caret_behavior) {}

bool InputMethodController::ReplaceComposition(const String& text) {}

// relativeCaretPosition is relative to the end of the text.
static int ComputeAbsoluteCaretPosition(int text_start,
                                        int text_length,
                                        int relative_caret_position) {}

void InputMethodController::AddImeTextSpans(
    const Vector<ImeTextSpan>& ime_text_spans,
    ContainerNode* base_element,
    unsigned offset_in_plain_chars) {}

bool InputMethodController::ReplaceCompositionAndMoveCaret(
    const String& text,
    int relative_caret_position,
    const Vector<ImeTextSpan>& ime_text_spans) {}

bool InputMethodController::InsertText(const String& text) {}

bool InputMethodController::InsertTextAndMoveCaret(
    const String& text,
    int relative_caret_position,
    const Vector<ImeTextSpan>& ime_text_spans) {}

void InputMethodController::CancelComposition() {}

bool InputMethodController::DispatchCompositionStartEvent(const String& text) {}

void InputMethodController::SetComposition(
    const String& text,
    const Vector<ImeTextSpan>& ime_text_spans,
    int selection_start,
    int selection_end) {}

PlainTextRange InputMethodController::CreateSelectionRangeForSetComposition(
    int selection_start,
    int selection_end,
    size_t text_length) const {}

void InputMethodController::SetCompositionFromExistingText(
    const Vector<ImeTextSpan>& ime_text_spans,
    unsigned composition_start,
    unsigned composition_end) {}

void InputMethodController::AddImeTextSpansToExistingText(
    const Vector<ImeTextSpan>& ime_text_spans,
    unsigned text_start,
    unsigned text_end) {}

EphemeralRange InputMethodController::CompositionEphemeralRange() const {}

String InputMethodController::ComposingText() const {}

PlainTextRange InputMethodController::GetSelectionOffsets() const {}

EphemeralRange InputMethodController::EphemeralRangeForOffsets(
    const PlainTextRange& offsets) const {}

bool InputMethodController::SetSelectionOffsets(
    const PlainTextRange& selection_offsets) {}

bool InputMethodController::SetSelectionOffsets(
    const PlainTextRange& selection_offsets,
    TypingContinuation typing_continuation,
    bool show_handle,
    bool show_context_menu) {}

bool InputMethodController::SetEditableSelectionOffsets(
    const PlainTextRange& selection_offsets,
    bool show_handle,
    bool show_context_menu) {}

bool InputMethodController::SetEditableSelectionOffsets(
    const PlainTextRange& selection_offsets,
    TypingContinuation typing_continuation,
    bool show_handle,
    bool show_context_menu) {}

void InputMethodController::RemoveSuggestionMarkerInCompositionRange() {}

PlainTextRange InputMethodController::CreateRangeForSelection(
    int start,
    int end,
    size_t text_length) const {}

bool InputMethodController::DeleteSelection() {}

bool InputMethodController::DeleteSelectionWithoutAdjustment() {}

bool InputMethodController::MoveCaret(int new_caret_position) {}

void InputMethodController::ExtendSelectionAndDelete(int before, int after) {}

// TODO(ctzsm): We should reduce the number of selectionchange events.
// Ideally, we want to do the deletion without selection, however, there is no
// such editing command exists currently.
void InputMethodController::DeleteSurroundingText(int before, int after) {}

void InputMethodController::DeleteSurroundingTextInCodePoints(int before,
                                                              int after) {}

void InputMethodController::ExtendSelectionAndReplace(
    int before,
    int after,
    const String& replacement_text) {}

void InputMethodController::GetLayoutBounds(gfx::Rect* control_bounds,
                                            gfx::Rect* selection_bounds) {}

void InputMethodController::DidChangeVisibility(
    const LayoutObject& layout_object) {}

void InputMethodController::DidLayoutSubtree(
    const LayoutObject& layout_object) {}

void InputMethodController::DidUpdateLayout(const LayoutObject& layout_object) {}

void InputMethodController::LayoutObjectWillBeDestroyed(
    const LayoutObject& layout_object) {}

WebTextInputInfo InputMethodController::TextInputInfo() const {}

int InputMethodController::TextInputFlags() const {}

int InputMethodController::ComputeWebTextInputNextPreviousFlags() const {}

ui::TextInputAction InputMethodController::InputActionOfFocusedElement() const {}

WebTextInputMode InputMethodController::InputModeOfFocusedElement() const {}

ui::mojom::VirtualKeyboardPolicy
InputMethodController::VirtualKeyboardPolicyOfFocusedElement() const {}

void InputMethodController::SetVirtualKeyboardVisibilityRequest(
    ui::mojom::VirtualKeyboardVisibilityRequest vk_visibility_request) {}

DOMNodeId InputMethodController::NodeIdOfFocusedElement() const {}

WebTextInputType InputMethodController::TextInputType() const {}

void InputMethodController::WillChangeFocus() {}

void InputMethodController::Trace(Visitor* visitor) const {}

WebVector<ui::ImeTextSpan> InputMethodController::GetImeTextSpans() const {}

}  // namespace blink