win_caption_button_container.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // Modified from
  5. // chrome/browser/ui/views/frame/glass_browser_caption_button_container.h
  6. #ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_WIN_CAPTION_BUTTON_CONTAINER_H_
  7. #define ELECTRON_SHELL_BROWSER_UI_VIEWS_WIN_CAPTION_BUTTON_CONTAINER_H_
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/scoped_observation.h"
  10. #include "ui/base/metadata/metadata_header_macros.h"
  11. #include "ui/base/metadata/metadata_impl_macros.h"
  12. #include "ui/base/pointer/touch_ui_controller.h"
  13. #include "ui/views/controls/button/button.h"
  14. #include "ui/views/view.h"
  15. #include "ui/views/widget/widget.h"
  16. #include "ui/views/widget/widget_observer.h"
  17. namespace electron {
  18. class WinFrameView;
  19. class WinCaptionButton;
  20. // Provides a container for Windows 10 caption buttons that can be moved between
  21. // frame and browser window as needed. When extended horizontally, becomes a
  22. // grab bar for moving the window.
  23. class WinCaptionButtonContainer : public views::View,
  24. private views::WidgetObserver {
  25. METADATA_HEADER(WinCaptionButtonContainer, views::View)
  26. public:
  27. explicit WinCaptionButtonContainer(WinFrameView* frame_view);
  28. ~WinCaptionButtonContainer() override;
  29. // Tests to see if the specified |point| (which is expressed in this view's
  30. // coordinates and which must be within this view's bounds) is within one of
  31. // the caption buttons. Returns one of HitTestCompat enum defined in
  32. // ui/base/hit_test.h, HTCAPTION if the area hit would be part of the window's
  33. // drag handle, and HTNOWHERE otherwise.
  34. // See also ClientView::NonClientHitTest.
  35. int NonClientHitTest(const gfx::Point& point) const;
  36. void SetButtonSize(gfx::Size size);
  37. // Add tooltip text to caption buttons.
  38. void UpdateButtonToolTipsForWindowControlsOverlay();
  39. // Sets caption button container background color.
  40. void UpdateBackground();
  41. // Sets caption button visibility and enabled state based on window state.
  42. // Only one of maximize or restore button should ever be visible at the same
  43. // time, and both are disabled in tablet UI mode.
  44. void UpdateButtons();
  45. // Reset window button states to STATE_NORMAL.
  46. void ResetWindowControls();
  47. private:
  48. // views::View:
  49. void AddedToWidget() override;
  50. void RemovedFromWidget() override;
  51. // views::WidgetObserver:
  52. void OnWidgetBoundsChanged(views::Widget* widget,
  53. const gfx::Rect& new_bounds) override;
  54. raw_ptr<WinFrameView> const frame_view_;
  55. raw_ptr<WinCaptionButton> const minimize_button_;
  56. raw_ptr<WinCaptionButton> const maximize_button_;
  57. raw_ptr<WinCaptionButton> const restore_button_;
  58. raw_ptr<WinCaptionButton> const close_button_;
  59. base::ScopedObservation<views::Widget, views::WidgetObserver>
  60. widget_observation_{this};
  61. base::CallbackListSubscription subscription_ =
  62. ui::TouchUiController::Get()->RegisterCallback(
  63. base::BindRepeating(&WinCaptionButtonContainer::UpdateButtons,
  64. base::Unretained(this)));
  65. };
  66. } // namespace electron
  67. #endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_WIN_CAPTION_BUTTON_CONTAINER_H_