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

ash / annotator / annotation_tray.h [blame]

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

#ifndef ASH_ANNOTATOR_ANNOTATION_TRAY_H_
#define ASH_ANNOTATOR_ANNOTATION_TRAY_H_

#include "ash/public/cpp/session/session_observer.h"
#include "ash/session/session_controller_impl.h"
#include "ash/system/tray/tray_background_view.h"
#include "ash/system/tray/view_click_listener.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "ui/base/metadata/metadata_header_macros.h"

namespace ui {
class GestureEvent;
}  // namespace ui

namespace views {
class ImageView;
class Widget;
}  // namespace views

namespace ash {

class HoverHighlightView;
class TrayBubbleWrapper;

// Pen colors.
// TODO(b/352729094): Consolidate the pen vs. marker terminology.
constexpr SkColor kAnnotatorMagentaPenColor = SkColorSetRGB(0xFF, 0x00, 0xE5);
constexpr SkColor kAnnotatorRedPenColor = SkColorSetRGB(0xE9, 0x42, 0x35);
constexpr SkColor kAnnotatorYellowPenColor = SkColorSetRGB(0xFB, 0xF1, 0x04);
constexpr SkColor kAnnotatorBluePenColor = SkColorSetRGB(0x42, 0x85, 0xF4);
constexpr SkColor kAnnotatorDefaultPenColor = kAnnotatorMagentaPenColor;

// Status area tray which allows you to access the annotation tools.
class AnnotationTray : public TrayBackgroundView,
                                public SessionObserver {
  METADATA_HEADER(AnnotationTray, TrayBackgroundView)

 public:
  explicit AnnotationTray(Shelf* shelf);
  AnnotationTray(const AnnotationTray&) = delete;
  AnnotationTray& operator=(const AnnotationTray&) = delete;
  ~AnnotationTray() override;

  // TrayBackgroundView:
  void OnGestureEvent(ui::GestureEvent* event) override;
  void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
  void UpdateTrayItemColor(bool is_active) override;
  void HandleLocaleChange() override;
  void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
  void CloseBubbleInternal() override;
  void ShowBubble() override;
  TrayBubbleView* GetBubbleView() override;
  views::Widget* GetBubbleWidget() const override;
  void OnThemeChanged() override;
  void HideBubble(const TrayBubbleView* bubble_view) override;

  // SessionObserver:
  void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;

  void OnTrayButtonPressed(const ui::Event& event);
  void HideAnnotationTray();
  void SetTrayEnabled(bool enabled);
  void ToggleAnnotator();
  void UpdateAccessibleName(bool is_annotator_enabled);

 private:
  void EnableAnnotatorWithPenColor();
  // Deactivates any annotation tool that is currently enabled and updates the
  // UI.
  void DeactivateActiveTool();

  // Updates the icon and tooltip of `image_view_` in the status area.
  void UpdateIcon();

  void OnPenColorPressed(SkColor color);

  // Returns the message ID of the accessible name for the color.
  int GetAccessibleNameForColor(SkColor color);

  // Resets the tray to its default state.
  void ResetTray();

  std::u16string GetTooltip();

  // Sets the image with the color that corresponds to the active state.
  void SetIconImage(bool is_active);

  // Image view of the tray icon.
  const raw_ptr<views::ImageView> image_view_;

  raw_ptr<HoverHighlightView> pen_view_;

  // The bubble that appears after clicking the annotation tools tray button.
  std::unique_ptr<TrayBubbleWrapper> bubble_;

  // The last selected pen color.
  SkColor current_pen_color_ = kAnnotatorDefaultPenColor;

  base::ScopedObservation<SessionControllerImpl, SessionObserver>
      session_observer_{this};
};

}  // namespace ash

#endif  // ASH_ANNOTATOR_ANNOTATION_TRAY_H_