chromium/ui/views/controls/textfield/textfield_model.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/textfield/textfield_model.h"

#include <algorithm>
#include <utility>

#include "base/check_op.h"
#include "base/no_destructor.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/current_thread.h"
#include "build/chromeos_buildflags.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/utf16_indexing.h"
#include "ui/views/style/platform_style.h"

namespace {

// Orders ranges decreasing with respect to their min index. This is useful for
// applying text edits such that an edit doesn't offset the positions of later
// edits. It should be reversed when undoing edits.
void order_ranges(std::vector<gfx::Range>* ranges) {}

// Adjusts |position| for the deletion of |ranges|. E.g., if |position| is 10,
// and |ranges| is {{1, 3}, {15, 18}, and {6, 13}}, this will return 4,
// subtracting 2 (3-1), 0 (15>10), and 4 (10-6) for each range respectively.
size_t adjust_position_for_removals(size_t position,
                                    std::vector<gfx::Range> ranges) {}

}  // namespace

namespace views {

namespace internal {

// Edit holds state information to undo/redo editing changes. Editing operations
// are merged when possible, like when characters are typed in sequence. Calling
// Commit() marks an edit as an independent operation that shouldn't be merged.
class Edit {};

// Insert text at a given position. Assumes 1) no previous selection and 2) the
// insertion is at the cursor, which will advance by the insertion length.
class InsertEdit : public Edit {};

// Delete one or more ranges and do a single insertion. The insertion need not
// be adjacent to the deletions (e.g. drag & drop).
class ReplaceEdit : public Edit {};

// Delete possibly multiple texts.
class DeleteEdit : public Edit {};

}  // namespace internal

namespace {

// Returns the first segment that is visually emphasized. Usually it's used for
// representing the target clause (on Windows). Returns an invalid range if
// there is no such a range.
gfx::Range GetFirstEmphasizedRange(const ui::CompositionText& composition) {}

// Returns a pointer to the kill buffer which holds the text to be inserted on
// executing yank command. Singleton since it needs to be persisted across
// multiple textfields.
// On Mac, the size of the kill ring (no. of buffers) is controlled by
// NSTextKillRingSize, a text system default. However to keep things simple,
// the default kill ring size of 1 (i.e. a single buffer) is assumed.
std::u16string* GetKillBuffer() {}

// Helper method to set the kill buffer.
void SetKillBuffer(const std::u16string& buffer) {}

void SelectRangeInCompositionText(gfx::RenderText* render_text,
                                  size_t cursor,
                                  const gfx::Range& range) {}

}  // namespace

/////////////////////////////////////////////////////////////////
// TextfieldModel: public

TextfieldModel::Delegate::~Delegate() = default;

TextfieldModel::TextfieldModel(Delegate* delegate)
    :{}

TextfieldModel::~TextfieldModel() {}

bool TextfieldModel::SetText(const std::u16string& new_text,
                             size_t cursor_position) {}

void TextfieldModel::Append(const std::u16string& new_text) {}

bool TextfieldModel::Delete(bool add_to_kill_buffer) {}

bool TextfieldModel::Backspace(bool add_to_kill_buffer) {}

size_t TextfieldModel::GetCursorPosition() const {}

void TextfieldModel::MoveCursor(gfx::BreakType break_type,
                                gfx::VisualCursorDirection direction,
                                gfx::SelectionBehavior selection_behavior) {}

bool TextfieldModel::MoveCursorTo(const gfx::SelectionModel& cursor) {}

bool TextfieldModel::MoveCursorTo(size_t pos) {}

bool TextfieldModel::MoveCursorTo(const gfx::Point& point, bool select) {}

std::u16string TextfieldModel::GetSelectedText() const {}

void TextfieldModel::SelectRange(const gfx::Range& range, bool primary) {}

void TextfieldModel::SelectSelectionModel(const gfx::SelectionModel& sel) {}

void TextfieldModel::SelectAll(bool reversed) {}

void TextfieldModel::SelectWord() {}

void TextfieldModel::ClearSelection() {}

bool TextfieldModel::CanUndo() {}

bool TextfieldModel::CanRedo() {}

bool TextfieldModel::Undo() {}

bool TextfieldModel::Redo() {}

bool TextfieldModel::Cut() {}

bool TextfieldModel::Copy() {}

bool TextfieldModel::Paste() {}

bool TextfieldModel::Transpose() {}

bool TextfieldModel::Yank() {}

bool TextfieldModel::HasSelection(bool primary_only) const {}

void TextfieldModel::DeleteSelection() {}

void TextfieldModel::DeletePrimarySelectionAndInsertTextAt(
    const std::u16string& new_text,
    size_t position) {}

std::u16string TextfieldModel::GetTextFromRange(const gfx::Range& range) const {}

void TextfieldModel::GetTextRange(gfx::Range* range) const {}

void TextfieldModel::SetCompositionText(
    const ui::CompositionText& composition) {}

void TextfieldModel::SetCompositionFromExistingText(const gfx::Range& range) {}

size_t TextfieldModel::ConfirmCompositionText() {}

void TextfieldModel::CancelCompositionText() {}

void TextfieldModel::ClearComposition() {}

void TextfieldModel::GetCompositionTextRange(gfx::Range* range) const {}

bool TextfieldModel::HasCompositionText() const {}

void TextfieldModel::ClearEditHistory() {}

/////////////////////////////////////////////////////////////////
// TextfieldModel: private

void TextfieldModel::InsertTextInternal(const std::u16string& new_text,
                                        bool mergeable) {}

void TextfieldModel::ReplaceTextInternal(const std::u16string& new_text,
                                         bool mergeable) {}

void TextfieldModel::ClearRedoHistory() {}

void TextfieldModel::ExecuteAndRecordDelete(std::vector<gfx::Range> ranges,
                                            bool mergeable) {}

void TextfieldModel::ExecuteAndRecordReplaceSelection(
    internal::MergeType merge_type,
    const std::u16string& new_text) {}

void TextfieldModel::ExecuteAndRecordReplace(
    internal::MergeType merge_type,
    std::vector<gfx::Range> replacement_ranges,
    size_t new_cursor_pos,
    const std::u16string& new_text,
    size_t new_text_start) {}

void TextfieldModel::ExecuteAndRecordInsert(const std::u16string& new_text,
                                            bool mergeable) {}

void TextfieldModel::AddOrMergeEditHistory(
    std::unique_ptr<internal::Edit> edit) {}

void TextfieldModel::ModifyText(
    const std::vector<gfx::Range>& deletions,
    const std::vector<std::u16string>& insertion_texts,
    const std::vector<size_t>& insertion_positions,
    const gfx::Range& primary_selection,
    const std::vector<gfx::Range>& secondary_selections) {}

void TextfieldModel::SetRenderTextText(const std::u16string& text) {}

// static
void TextfieldModel::ClearKillBuffer() {}

}  // namespace views