capture_mode_util.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_CAPTURE_MODE_CAPTURE_MODE_UTIL_H_
  5. #define ASH_CAPTURE_MODE_CAPTURE_MODE_UTIL_H_
  6. #include <string>
  7. #include "ash/ash_export.h"
  8. #include "ash/capture_mode/capture_mode_types.h"
  9. #include "base/time/time.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "ui/gfx/animation/tween.h"
  12. #include "ui/gfx/geometry/size.h"
  13. namespace aura {
  14. class Window;
  15. } // namespace aura
  16. namespace gfx {
  17. class Point;
  18. class Rect;
  19. class Transform;
  20. } // namespace gfx
  21. namespace ui {
  22. class Layer;
  23. } // namespace ui
  24. namespace views {
  25. class View;
  26. class Widget;
  27. } // namespace views
  28. namespace ash {
  29. class StopRecordingButtonTray;
  30. namespace capture_mode_util {
  31. // Returns true if the capture mode feature is enabled and capture mode is
  32. // active. This method allows callers to avoid including the full header for
  33. // CaptureModeController, which has many transitive includes.
  34. bool IsCaptureModeActive();
  35. // Retrieves the point on the |rect| associated with |position|.
  36. ASH_EXPORT gfx::Point GetLocationForFineTunePosition(const gfx::Rect& rect,
  37. FineTunePosition position);
  38. // Return whether |position| is a corner.
  39. bool IsCornerFineTunePosition(FineTunePosition position);
  40. // Returns the stop recording tray button on the given `root`. It may return
  41. // `nullptr` during shutdown or if `root` is destroying.
  42. StopRecordingButtonTray* GetStopRecordingButtonForRoot(aura::Window* root);
  43. // Sets the visibility of the stop-recording button in the Shelf's status area
  44. // widget of the given |root| window.
  45. void SetStopRecordingButtonVisibility(aura::Window* root, bool visible);
  46. // Triggers an accessibility alert to give the user feedback.
  47. void TriggerAccessibilityAlert(const std::string& message);
  48. void TriggerAccessibilityAlert(int message_id);
  49. // Same as TriggerAccessibilityAlert above, but triggers the alert
  50. // asynchronously as soon as possible. This is used to make sure consecutive
  51. // alerts do not override one another, so all of them can be announced by
  52. // ChromeVox.
  53. void TriggerAccessibilityAlertSoon(const std::string& message);
  54. void TriggerAccessibilityAlertSoon(int message_id);
  55. // Returns the next horizontal or vertical snap position based on the current
  56. // camera preview snap position `current` and the movement. Returns `current` if
  57. // the movement is not doable based on current snap position.
  58. CameraPreviewSnapPosition GetCameraNextHorizontalSnapPosition(
  59. CameraPreviewSnapPosition current,
  60. bool going_left);
  61. CameraPreviewSnapPosition GetCameraNextVerticalSnapPosition(
  62. CameraPreviewSnapPosition current,
  63. bool going_up);
  64. // Notification Utils //
  65. // Constants related to the banner view on the image capture notifications.
  66. constexpr int kBannerHeightDip = 36;
  67. constexpr int kBannerHorizontalInsetDip = 12;
  68. constexpr int kBannerVerticalInsetDip = 8;
  69. constexpr int kBannerIconTextSpacingDip = 8;
  70. constexpr int kBannerIconSizeDip = 20;
  71. // Constants related to the play icon view for video capture notifications.
  72. constexpr int kPlayIconSizeDip = 24;
  73. constexpr int kPlayIconBackgroundCornerRadiusDip = 20;
  74. constexpr gfx::Size kPlayIconViewSize{40, 40};
  75. std::unique_ptr<views::View> CreateClipboardShortcutView();
  76. // Creates the banner view that will show on top of the notification image.
  77. std::unique_ptr<views::View> CreateBannerView();
  78. // Creates the play icon view which shows on top of the video thumbnail in the
  79. // notification.
  80. std::unique_ptr<views::View> CreatePlayIconView();
  81. // Returns a transform that scales the given `layer` by the given `scale` factor
  82. // in both X and Y around its local center point.
  83. gfx::Transform GetScaleTransformAboutCenter(ui::Layer* layer, float scale);
  84. // Defines an object to hold the values of the camera preview size specs.
  85. struct CameraPreviewSizeSpecs {
  86. // The size to which the camera preview should be set under the current
  87. // conditions.
  88. const gfx::Size size;
  89. // True if the expanded size of the camera preview is big enough to allow it
  90. // to be collapsible. False otherwise.
  91. const bool is_collapsible;
  92. // Whether the camera preview should be hidden or shown. The visibility of the
  93. // preview can be determined by a number of things, e.g.:
  94. // - The surface within which the camera preview should be confined is too
  95. // small.
  96. // - We're inside a `kRegion` session and the region is being adjusted or
  97. // empty.
  98. const bool should_be_visible;
  99. // True if the surface within which the camera preview is confined is too
  100. // small, and the preview should be hidden.
  101. const bool is_surface_too_small;
  102. };
  103. // Calculates the size specs of the camera preview which will be confined within
  104. // the given `confine_bounds_size` and will be either expanded or collapsed
  105. // based on the given `is_collapsed`.
  106. ASH_EXPORT CameraPreviewSizeSpecs
  107. CalculateCameraPreviewSizeSpecs(const gfx::Size& confine_bounds_size,
  108. bool is_collapsed);
  109. // Gets the top-most window that is capturable under the mouse/touch position.
  110. // The windows that are not capturable include the camera preview widget and
  111. // capture label. There will be a crash if the capture label widget gets picked
  112. // since the snapshot code tries to snap a deleted window.
  113. aura::Window* GetTopMostCapturableWindowAtPoint(const gfx::Point& screen_point);
  114. bool GetWidgetCurrentVisibility(views::Widget* widget);
  115. // Defines an object to hold the animation params used for setting the widget's
  116. // visibility.
  117. struct AnimationParams {
  118. const base::TimeDelta animation_duration;
  119. const gfx::Tween::Type tween_type;
  120. // When it's true, the scale up transform should be applied in the fade in
  121. // animiation.
  122. const bool apply_scale_up_animation;
  123. };
  124. // Sets the visibility of the given `widget` to the given `target_visibility`
  125. // with the given `animation_params`, returns true only if the
  126. // `target_visibility` is different than the current.
  127. bool SetWidgetVisibility(views::Widget* widget,
  128. bool target_visibility,
  129. absl::optional<AnimationParams> animation_params);
  130. } // namespace capture_mode_util
  131. } // namespace ash
  132. #endif // ASH_CAPTURE_MODE_CAPTURE_MODE_UTIL_H_