chromium/chrome/browser/ui/views/omnibox/omnibox_view_views.cc

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

#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"

#include <memory>
#include <set>
#include <utility>

#include "base/auto_reset.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/history_clusters/history_clusters_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/lens/lens_overlay_entry_point_controller.h"
#include "chrome/browser/ui/omnibox/clipboard_utils.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_view_views.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_view_webui.h"
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_bubble_controller.h"
#include "chrome/grit/generated_resources.h"
#include "components/lens/lens_features.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_client.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_popup_selection.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/prefs/pref_service.h"
#include "components/security_state/core/security_state.h"
#include "components/send_tab_to_self/metrics_util.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/elide_url.h"
#include "components/url_formatter/url_fixer.h"
#include "components/url_formatter/url_formatter.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/focused_node_details.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_buffer.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_edit_commands.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/ime/virtual_keyboard_controller.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/selection_model.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/border.h"
#include "ui/views/button_drag_utils.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_WIN)
#include "chrome/browser/browser_process.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "ui/display/screen.h"
#endif

namespace {

OmniboxEventProto;
DragOperation;

// OmniboxState ---------------------------------------------------------------

// Stores omnibox state for each tab.
struct OmniboxState : public base::SupportsUserData::Data {};

// static
const char OmniboxState::kKey[] =;

OmniboxState::OmniboxState(
    const OmniboxEditModel::State& model_state,
    const std::vector<gfx::Range> selection,
    const std::vector<gfx::Range> saved_selection_for_focus_change)
    :{}

OmniboxState::~OmniboxState() = default;

bool IsClipboardDataMarkedAsConfidential() {}

}  // namespace

// OmniboxViewViews -----------------------------------------------------------

OmniboxViewViews::OmniboxViewViews(std::unique_ptr<OmniboxClient> client,
                                   bool popup_window_mode,
                                   LocationBarView* location_bar_view,
                                   const gfx::FontList& font_list)
    :{}

OmniboxViewViews::~OmniboxViewViews() {}

void OmniboxViewViews::Init() {}

void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) {}

void OmniboxViewViews::OnTabChanged(content::WebContents* web_contents) {}

void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) {}

void OmniboxViewViews::InstallPlaceholderText() {}

bool OmniboxViewViews::GetSelectionAtEnd() const {}

void OmniboxViewViews::EmphasizeURLComponents() {}

void OmniboxViewViews::Update() {}

std::u16string OmniboxViewViews::GetText() const {}

void OmniboxViewViews::SetUserText(const std::u16string& text,
                                   bool update_popup) {}

void OmniboxViewViews::SetAdditionalText(
    const std::u16string& additional_text) {}

void OmniboxViewViews::EnterKeywordModeForDefaultSearchProvider() {}

void OmniboxViewViews::GetSelectionBounds(
    std::u16string::size_type* start,
    std::u16string::size_type* end) const {}

size_t OmniboxViewViews::GetAllSelectionsLength() const {}

void OmniboxViewViews::SelectAll(bool reversed) {}

void OmniboxViewViews::RevertAll() {}

void OmniboxViewViews::SetFocus(bool is_user_initiated) {}

int OmniboxViewViews::GetTextWidth() const {}

int OmniboxViewViews::GetUnelidedTextWidth() const {}

bool OmniboxViewViews::IsImeComposing() const {}

gfx::Size OmniboxViewViews::GetMinimumSize() const {}

void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {}

void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {}

void OmniboxViewViews::OnInputMethodChanged() {}

ui::TextInputType OmniboxViewViews::GetPreferredTextInputType() const {}

void OmniboxViewViews::AddedToWidget() {}

void OmniboxViewViews::RemovedFromWidget() {}

void OmniboxViewViews::UpdateSchemeStyle(const gfx::Range& range) {}

void OmniboxViewViews::OnThemeChanged() {}

bool OmniboxViewViews::IsDropCursorForInsertion() const {}

void OmniboxViewViews::ApplyColor(SkColor color, const gfx::Range& range) {}

void OmniboxViewViews::ApplyStyle(gfx::TextStyle style,
                                  bool value,
                                  const gfx::Range& range) {}

void OmniboxViewViews::SetTextAndSelectedRanges(
    const std::u16string& text,
    const std::vector<gfx::Range>& ranges) {}

void OmniboxViewViews::SetSelectedRanges(
    const std::vector<gfx::Range>& ranges) {}

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

void OmniboxViewViews::OnOmniboxPaste() {}

void OmniboxViewViews::UpdateAccessibleTextSelection() {}

bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {}

#if BUILDFLAG(IS_MAC)
void OmniboxViewViews::AnnounceFriendlySuggestionText() {
  GetViewAccessibility().AnnounceText(friendly_suggestion_text_);
}
#endif

void OmniboxViewViews::SetWindowTextAndCaretPos(const std::u16string& text,
                                                size_t caret_pos,
                                                bool update_popup,
                                                bool notify_text_changed) {}

void OmniboxViewViews::SetCaretPos(size_t caret_pos) {}

bool OmniboxViewViews::IsSelectAll() const {}

void OmniboxViewViews::UpdatePopup() {}

void OmniboxViewViews::ApplyCaretVisibility() {}

void OmniboxViewViews::OnTemporaryTextMaybeChanged(
    const std::u16string& display_text,
    const AutocompleteMatch& match,
    bool save_original_selection,
    bool notify_text_changed) {}

void OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged(
    const std::u16string& display_text,
    std::vector<gfx::Range> selections,
    const std::u16string& prefix_autocompletion,
    const std::u16string& inline_autocompletion) {}

void OmniboxViewViews::OnInlineAutocompleteTextCleared() {}

void OmniboxViewViews::OnRevertTemporaryText(const std::u16string& display_text,
                                             const AutocompleteMatch& match) {}

void OmniboxViewViews::ClearAccessibilityLabel() {}

void OmniboxViewViews::SetAccessibilityLabel(const std::u16string& display_text,
                                             const AutocompleteMatch& match,
                                             bool notify_text_changed) {}

bool OmniboxViewViews::UnapplySteadyStateElisions(UnelisionGesture gesture) {}

void OmniboxViewViews::OnBeforePossibleChange() {}

bool OmniboxViewViews::OnAfterPossibleChange(bool allow_keyword_ui_change) {}

gfx::NativeView OmniboxViewViews::GetNativeView() const {}

gfx::NativeView OmniboxViewViews::GetRelativeWindowForPopup() const {}

int OmniboxViewViews::GetWidth() const {}

bool OmniboxViewViews::IsImeShowingPopup() const {}

void OmniboxViewViews::ShowVirtualKeyboardIfEnabled() {}

void OmniboxViewViews::HideImeIfNeeded() {}

int OmniboxViewViews::GetOmniboxTextLength() const {}

void OmniboxViewViews::SetEmphasis(bool emphasize, const gfx::Range& range) {}

void OmniboxViewViews::OnMouseMoved(const ui::MouseEvent& event) {}

void OmniboxViewViews::OnMouseExited(const ui::MouseEvent& event) {}

bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {}

std::u16string OmniboxViewViews::GetLabelForCommandId(int command_id) const {}

bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {}

bool OmniboxViewViews::OnMouseDragged(const ui::MouseEvent& event) {}

void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) {}

void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {}

bool OmniboxViewViews::SkipDefaultKeyEventProcessing(
    const ui::KeyEvent& event) {}

void OmniboxViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {}

bool OmniboxViewViews::HandleAccessibleAction(
    const ui::AXActionData& action_data) {}

void OmniboxViewViews::OnFocus() {}

void OmniboxViewViews::OnBlur() {}

bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {}

OmniboxPopupView* OmniboxViewViews::GetPopupViewForTesting() const {}

std::u16string OmniboxViewViews::GetSelectionClipboardText() const {}

void OmniboxViewViews::DoInsertChar(char16_t ch) {}

bool OmniboxViewViews::IsTextEditCommandEnabled(
    ui::TextEditCommand command) const {}

void OmniboxViewViews::ExecuteTextEditCommand(ui::TextEditCommand command) {}

bool OmniboxViewViews::ShouldShowPlaceholderText() const {}

void OmniboxViewViews::UpdateAccessibleValue() {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void OmniboxViewViews::CandidateWindowOpened(
    ash::input_method::InputMethodManager* manager) {
  ime_candidate_window_open_ = true;
}

void OmniboxViewViews::CandidateWindowClosed(
    ash::input_method::InputMethodManager* manager) {
  ime_candidate_window_open_ = false;
}
#endif

void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
                                       const std::u16string& new_contents) {}

bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
                                      const ui::KeyEvent& event) {}

void OmniboxViewViews::OnBeforeUserAction(views::Textfield* sender) {}

void OmniboxViewViews::OnAfterUserAction(views::Textfield* sender) {}

void OmniboxViewViews::OnAfterCutOrCopy(ui::ClipboardBuffer clipboard_buffer) {}

void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) {}

void OmniboxViewViews::OnGetDragOperationsForTextfield(int* drag_operations) {}

void OmniboxViewViews::AppendDropFormats(
    int* formats,
    std::set<ui::ClipboardFormatType>* format_types) {}

DragOperation OmniboxViewViews::OnDrop(const ui::DropTargetEvent& event) {}

views::View::DropCallback OmniboxViewViews::CreateDropCallback(
    const ui::DropTargetEvent& event) {}

void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) {}

bool OmniboxViewViews::IsCommandIdChecked(int id) const {}

void OmniboxViewViews::OnCompositingDidCommit(ui::Compositor* compositor) {}

void OmniboxViewViews::OnCompositingStarted(ui::Compositor* compositor,
                                            base::TimeTicks start_time) {}

void OmniboxViewViews::OnCompositingAckDeprecated(ui::Compositor* compositor) {}

void OmniboxViewViews::OnCompositingShuttingDown(ui::Compositor* compositor) {}

void OmniboxViewViews::OnTemplateURLServiceChanged() {}

void OmniboxViewViews::PermitExternalProtocolHandler() {}

void OmniboxViewViews::PerformDrop(
    const ui::DropTargetEvent& event,
    ui::mojom::DragOperation& output_drag_op,
    std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner) {}

void OmniboxViewViews::MaybeAddSendTabToSelfItem(
    ui::SimpleMenuModel* menu_contents) {}

void OmniboxViewViews::OnPopupOpened() {}

BEGIN_METADATA()