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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// 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.
#ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/views/omnibox/omnibox_mouse_enter_exit_handler.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_popup_selection.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/background.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"
class OmniboxMatchCellView;
class OmniboxPopupViewViews;
class OmniboxSuggestionButtonRowView;
class OmniboxResultSelectionIndicator;
enum class OmniboxPart;
enum class OmniboxPartState;
namespace gfx {
class Image;
}
namespace views {
class Button;
class ImageButton;
} // namespace views
class OmniboxResultView : public views::View {
public:
METADATA_HEADER(OmniboxResultView);
OmniboxResultView(OmniboxPopupViewViews* popup_view, size_t model_index);
OmniboxResultView(const OmniboxResultView&) = delete;
OmniboxResultView& operator=(const OmniboxResultView&) = delete;
~OmniboxResultView() override;
// Static method to share logic about how to set backgrounds of popup cells.
static std::unique_ptr<views::Background> GetPopupCellBackground(
views::View* view,
OmniboxPartState part_state);
// Updates the match used to paint the contents of this result view. We copy
// the match so that we can continue to paint the last result even after the
// model has changed.
void SetMatch(const AutocompleteMatch& match);
// Applies the current theme to the current text and widget colors.
// Also refreshes the icons which may need to be re-colored as well.
void ApplyThemeAndRefreshIcons(bool force_reapply_styles = false);
// Invoked when this result view has been selected or unselected.
void OnSelectionStateChanged();
// Whether this result view should be considered 'selected'. This returns
// false if this line's header is selected (instead of the match itself).
bool GetMatchSelected() const;
// Returns the focused button or nullptr if none exists for this suggestion.
views::Button* GetActiveAuxiliaryButtonForAccessibility();
OmniboxPartState GetThemeState() const;
// Notification that the match icon has changed and schedules a repaint.
void OnMatchIconUpdated();
// Stores the image in a local data member and schedules a repaint.
void SetRichSuggestionImage(const gfx::ImageSkia& image);
void ButtonPressed(OmniboxPopupSelection::LineState state,
const ui::Event& event);
// Helper to emit accessibility events (may only emit if conditions are met).
void EmitTextChangedAccessiblityEvent();
// views::View:
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnThemeChanged() override;
private:
FRIEND_TEST_ALL_PREFIXES(OmniboxPopupViewViewsTest, DeleteSuggestion);
gfx::Image GetIcon() const;
// Updates the highlight state of the row, as well as conditionally shows
// controls that are only visible on row hover.
void UpdateHoverState();
// Sets the visibility of the |remove_suggestion_button_| based on the current
// state.
void UpdateRemoveSuggestionVisibility();
// views::View:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
// The parent view.
const raw_ptr<OmniboxPopupViewViews> popup_view_;
// This result's model index.
size_t model_index_;
// The data this class is built to display (the "Omnibox Result").
AutocompleteMatch match_;
// Accessible name (enables to emit certain events).
std::u16string accessible_name_;
// Weak pointers for easy reference.
raw_ptr<OmniboxMatchCellView>
suggestion_view_; // The leading (or left) view.
// The blue bar used to indicate selection.
raw_ptr<OmniboxResultSelectionIndicator> selection_indicator_ = nullptr;
// The "X" button at the end of the match cell, used to remove suggestions.
raw_ptr<views::ImageButton> remove_suggestion_button_;
// The row of buttons that appears when actions such as tab switch or Pedals
// are on the suggestion. It is owned by the base view, not this raw pointer.
raw_ptr<OmniboxSuggestionButtonRowView> button_row_ = nullptr;
// Keeps track of mouse-enter and mouse-exit events of child Views.
OmniboxMouseEnterExitHandler mouse_enter_exit_handler_;
base::WeakPtrFactory<OmniboxResultView> weak_factory_{this};
};
#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
|