File: page_action_view.h

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (121 lines) | stat: -rw-r--r-- 4,873 bytes parent folder | download | duplicates (5)
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
// Copyright 2024 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_PAGE_ACTION_PAGE_ACTION_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PAGE_ACTION_PAGE_ACTION_VIEW_H_

#include "base/callback_list.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
#include "chrome/browser/ui/views/page_action/page_action_model_observer.h"
#include "chrome/browser/ui/views/page_action/page_action_triggers.h"
#include "ui/actions/actions.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/events/event.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/view.h"

namespace page_actions {

class PageActionController;
class PageActionModelInterface;
struct PageActionViewParams;

// PageActionView is the view displaying the page action. There is one per
// browser, per page action.
class PageActionView : public IconLabelBubbleView,
                       public PageActionModelObserver {
  METADATA_HEADER(PageActionView, IconLabelBubbleView)
 public:
  PageActionView(actions::ActionItem* action_item,
                 const PageActionViewParams& params,
                 ui::ElementIdentifier element_identifier);
  PageActionView(const PageActionView&) = delete;
  PageActionView& operator=(const PageActionView&) = delete;
  ~PageActionView() override;

  // Sets the controller for this view, and attaches this view in the
  // controller.
  void OnNewActiveController(PageActionController* controller);

  // As an alternative to OnNewActiveController(), just set the observed model.
  // TODO(crbug.com/388524315): Merge OnNewActiveController and this method.
  void SetModel(PageActionModelInterface* model);

  // Indicates whether this view is showing a suggestion chip.
  // A chip is considered showing even if it is mid-animation (i.e. while
  // expanding and collapsing).
  bool IsChipVisible() const;

  using ChipVisibilityChanged = base::RepeatingCallback<void(PageActionView*)>;
  base::CallbackListSubscription AddChipVisibilityChangedCallback(
      ChipVisibilityChanged callback);

  // PageActionModelObserver:
  void OnPageActionModelChanged(const PageActionModelInterface& model) override;
  void OnPageActionModelWillBeDeleted(
      const PageActionModelInterface& model) override;

  // IconLabelBubbleView:
  void ViewHierarchyChanged(
      const views::ViewHierarchyChangedDetails& details) override;
  void OnThemeChanged() override;
  void OnTouchUiChanged() override;
  void UpdateBorder() override;
  bool ShouldShowLabelAfterAnimation() const override;
  bool ShouldShowSeparator() const override;
  bool ShouldUpdateInkDropOnClickCanceled() const override;
  void NotifyClick(const ui::Event& event) override;
  gfx::Size GetMinimumSize() const override;
  bool IsBubbleShowing() const override;
  bool IsTriggerableEvent(const ui::Event& event) override;

  actions::ActionId GetActionId() const;

  views::View* GetLabelForTesting();
  gfx::SlideAnimation& GetSlideAnimationForTesting();

 private:
  // The image associated with the `action_item_` size may be different from the
  // size needed for the location bar page action icon. Therefore, we should to
  // update the image size if needed.
  void UpdateIconImage();

  // Changes to label visibility indicate that the chip state of this page
  // action changed. This handler ensures the view is updated accordingly.
  void OnLabelVisibilityChanged();

  base::WeakPtr<actions::ActionItem> action_item_ = nullptr;
  base::ScopedObservation<PageActionModelInterface, PageActionModelObserver>
      observation_{this};

  // The view creates and holds the current controller's subscription to
  // ActionItem updates. This ensures that updates aren't unnecessarily
  // propagated to every tab's controller.
  base::CallbackListSubscription action_item_controller_subscription_;

  const int icon_size_;
  const gfx::Insets icon_insets_;

  // Subscription to changes in label visibility, used for updating properties
  // dependent on label visibility and notifying others of chip state changes.
  base::CallbackListSubscription label_visibility_changed_subscription_;

  // Client-provided callbacks for changes to chip state.
  base::RepeatingCallbackList<void(PageActionView*)>
      chip_visibility_changed_callbacks_;

  // Used to record click event histogram. It's initialized to base::DoNothing()
  // for testing purpose.
  base::RepeatingCallback<void(PageActionTrigger)> click_callback_ =
      base::DoNothing();
};

}  // namespace page_actions

#endif  // CHROME_BROWSER_UI_VIEWS_PAGE_ACTION_PAGE_ACTION_VIEW_H_