File: omnibox_row_view.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,696 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2020 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_row_view.h"

#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/omnibox/omnibox_header_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_match_cell_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_popup_view_views.h"
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_popup_selection.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/type_conversion.h"
#include "ui/views/style/typography.h"

DEFINE_ENUM_CONVERTERS(OmniboxPopupSelection::LineState,
                       {OmniboxPopupSelection::NORMAL, u"NORMAL"},
                       {OmniboxPopupSelection::KEYWORD_MODE, u"KEYWORD_MODE"},
                       {OmniboxPopupSelection::FOCUSED_BUTTON_ACTION,
                        u"FOCUSED_BUTTON_ACTION"},
                       {OmniboxPopupSelection::FOCUSED_BUTTON_THUMBS_UP,
                        u"FOCUSED_BUTTON_THUMBS_UP"},
                       {OmniboxPopupSelection::FOCUSED_BUTTON_THUMBS_DOWN,
                        u"FOCUSED_BUTTON_THUMBS_DOWN"},
                       {OmniboxPopupSelection::FOCUSED_BUTTON_REMOVE_SUGGESTION,
                        u"FOCUSED_BUTTON_REMOVE_SUGGESTION"})

template <>
struct ui::metadata::TypeConverter<OmniboxPopupSelection>
    : public ui::metadata::BaseTypeConverter<true> {
  static std::u16string ToString(
      ui::metadata::ArgType<OmniboxPopupSelection> source_value);
  static std::optional<OmniboxPopupSelection> FromString(
      const std::u16string& source_value);
  static ui::metadata::ValidStrings GetValidStrings() { return {}; }
};

// static
std::u16string ui::metadata::TypeConverter<OmniboxPopupSelection>::ToString(
    ui::metadata::ArgType<OmniboxPopupSelection> source_value) {
  return u"{" + base::NumberToString16(source_value.line) + u"," +
         TypeConverter<OmniboxPopupSelection::LineState>::ToString(
             source_value.state) +
         u"}";
}

// static
std::optional<OmniboxPopupSelection> ui::metadata::TypeConverter<
    OmniboxPopupSelection>::FromString(const std::u16string& source_value) {
  const auto values = base::SplitString(
      source_value, u"{,}", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
  if (values.size() != 2) {
    return std::nullopt;
  }
  // TODO(pkasting): This should be size_t, but for some reason that won't link
  // on Mac.
  const std::optional<uint32_t> line =
      TypeConverter<uint32_t>::FromString(values[0]);
  const std::optional<OmniboxPopupSelection::LineState> state =
      TypeConverter<OmniboxPopupSelection::LineState>::FromString(values[1]);
  return (line.has_value() && state.has_value())
             ? std::make_optional<OmniboxPopupSelection>(line.value(),
                                                         state.value())
             : std::nullopt;
}

OmniboxRowView::OmniboxRowView(size_t line, OmniboxPopupViewViews* popup_view)
    : popup_view_(popup_view) {
  SetLayoutManager(std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kVertical));
  result_view_ =
      AddChildView(std::make_unique<OmniboxResultView>(popup_view, line));
}

void OmniboxRowView::ShowHeader(const std::u16string& header_text) {
  // Create the header (at index 0) if it doesn't exist.
  if (header_view_ == nullptr) {
    header_view_ =
        AddChildViewAt(std::make_unique<OmniboxHeaderView>(popup_view_), 0);
  }

  header_view_->SetHeader(header_text);
  header_view_->SetVisible(true);
}

void OmniboxRowView::HideHeader() {
  if (header_view_) {
    header_view_->SetVisible(false);
  }
}

void OmniboxRowView::OnSelectionStateChanged() {
  result_view_->OnSelectionStateChanged();
}

views::View* OmniboxRowView::GetActiveAuxiliaryButtonForAccessibility() const {
  return result_view_->GetActiveAuxiliaryButtonForAccessibility();
}

gfx::Insets OmniboxRowView::GetInsets() const {
  if (result_view_->GetThemeState() == OmniboxPartState::IPH) {
    int LRInsets = OmniboxMatchCellView::kIphOffset;
    return gfx::Insets::TLBR(8, LRInsets, 8, LRInsets);
  }

  return gfx::Insets::TLBR(0, 0, 0, 16);
}

BEGIN_METADATA(OmniboxRowView)
END_METADATA