2022-01-26 21:59:09 +00:00
|
|
|
// Copyright (c) 2021 Ryan Gonzalez.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_CLIENT_FRAME_VIEW_LINUX_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_CLIENT_FRAME_VIEW_LINUX_H_
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
|
|
|
#include "base/memory/raw_ptr_exclusion.h"
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "base/scoped_observation.h"
|
|
|
|
#include "shell/browser/ui/views/frameless_view.h"
|
2024-07-25 09:25:45 +00:00
|
|
|
#include "third_party/skia/include/core/SkRRect.h"
|
2024-02-21 20:27:05 +00:00
|
|
|
#include "ui/base/metadata/metadata_header_macros.h"
|
2022-10-27 16:37:04 +00:00
|
|
|
#include "ui/base/ui_base_types.h"
|
2022-07-20 11:03:34 +00:00
|
|
|
#include "ui/linux/linux_ui.h"
|
|
|
|
#include "ui/linux/nav_button_provider.h"
|
|
|
|
#include "ui/linux/window_button_order_observer.h"
|
|
|
|
#include "ui/linux/window_frame_provider.h"
|
2022-01-26 21:59:09 +00:00
|
|
|
#include "ui/native_theme/native_theme.h"
|
|
|
|
#include "ui/native_theme/native_theme_observer.h"
|
|
|
|
#include "ui/views/controls/button/image_button.h"
|
|
|
|
#include "ui/views/controls/label.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
#include "ui/views/window/frame_buttons.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2024-07-25 09:25:45 +00:00
|
|
|
class NativeWindowViews;
|
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
class ClientFrameViewLinux : public FramelessView,
|
2024-05-29 18:07:02 +00:00
|
|
|
private ui::NativeThemeObserver,
|
|
|
|
private ui::WindowButtonOrderObserver {
|
2024-02-21 20:27:05 +00:00
|
|
|
METADATA_HEADER(ClientFrameViewLinux, FramelessView)
|
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
public:
|
|
|
|
ClientFrameViewLinux();
|
|
|
|
~ClientFrameViewLinux() override;
|
|
|
|
|
|
|
|
void Init(NativeWindowViews* window, views::Widget* frame) override;
|
|
|
|
|
|
|
|
// These are here for ElectronDesktopWindowTreeHostLinux to use.
|
|
|
|
gfx::Insets GetBorderDecorationInsets() const;
|
|
|
|
gfx::Insets GetInputInsets() const;
|
|
|
|
gfx::Rect GetWindowContentBounds() const;
|
|
|
|
SkRRect GetRoundedWindowContentBounds() const;
|
2024-05-10 15:21:10 +00:00
|
|
|
int GetTranslucentTopAreaHeight() const;
|
2022-10-27 16:37:04 +00:00
|
|
|
// Returns which edges of the frame are tiled.
|
|
|
|
const ui::WindowTiledEdges& tiled_edges() const { return tiled_edges_; }
|
|
|
|
void set_tiled_edges(ui::WindowTiledEdges tiled_edges) {
|
|
|
|
tiled_edges_ = tiled_edges;
|
|
|
|
}
|
2022-01-26 21:59:09 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// ui::NativeThemeObserver:
|
|
|
|
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
|
|
|
|
|
|
|
// views::WindowButtonOrderObserver:
|
2022-06-01 06:12:47 +00:00
|
|
|
void OnWindowButtonOrderingChange() override;
|
2022-01-26 21:59:09 +00:00
|
|
|
|
2022-06-16 07:46:11 +00:00
|
|
|
// Overridden from FramelessView:
|
2022-01-26 21:59:09 +00:00
|
|
|
int ResizingBorderHitTest(const gfx::Point& point) override;
|
|
|
|
|
2022-06-16 07:46:11 +00:00
|
|
|
// Overridden from views::NonClientFrameView:
|
2022-01-26 21:59:09 +00:00
|
|
|
gfx::Rect GetBoundsForClientView() const override;
|
|
|
|
gfx::Rect GetWindowBoundsForClientBounds(
|
|
|
|
const gfx::Rect& client_bounds) const override;
|
|
|
|
int NonClientHitTest(const gfx::Point& point) override;
|
|
|
|
void GetWindowMask(const gfx::Size& size, SkPath* window_mask) override;
|
|
|
|
void UpdateWindowTitle() override;
|
|
|
|
void SizeConstraintsChanged() override;
|
|
|
|
|
|
|
|
// Overridden from View:
|
2024-06-07 21:18:35 +00:00
|
|
|
gfx::Size CalculatePreferredSize(
|
|
|
|
const views::SizeBounds& available_size) const override;
|
2022-01-26 21:59:09 +00:00
|
|
|
gfx::Size GetMinimumSize() const override;
|
|
|
|
gfx::Size GetMaximumSize() const override;
|
2024-02-14 17:33:32 +00:00
|
|
|
void Layout(PassKey) override;
|
2022-01-26 21:59:09 +00:00
|
|
|
void OnPaint(gfx::Canvas* canvas) override;
|
|
|
|
|
2024-07-02 07:51:33 +00:00
|
|
|
// Overridden from views::ViewTargeterDelegate
|
2022-08-03 08:51:52 +00:00
|
|
|
views::View* TargetForRect(views::View* root, const gfx::Rect& rect) override;
|
|
|
|
|
2024-07-02 07:51:33 +00:00
|
|
|
ui::WindowFrameProvider* GetFrameProvider() const;
|
|
|
|
|
2022-01-26 21:59:09 +00:00
|
|
|
private:
|
|
|
|
static constexpr int kNavButtonCount = 4;
|
|
|
|
|
|
|
|
struct NavButton {
|
2022-07-20 11:03:34 +00:00
|
|
|
ui::NavButtonProvider::FrameButtonDisplayType type;
|
2022-01-26 21:59:09 +00:00
|
|
|
views::FrameButton frame_button;
|
|
|
|
void (views::Widget::*callback)();
|
|
|
|
int accessibility_id;
|
|
|
|
int hit_test_id;
|
2023-05-11 20:07:39 +00:00
|
|
|
RAW_PTR_EXCLUSION views::ImageButton* button{nullptr};
|
2022-01-26 21:59:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ThemeValues {
|
|
|
|
float window_border_radius;
|
|
|
|
|
|
|
|
int titlebar_min_height;
|
|
|
|
gfx::Insets titlebar_padding;
|
|
|
|
|
|
|
|
SkColor title_color;
|
|
|
|
gfx::Insets title_padding;
|
|
|
|
|
|
|
|
int button_min_size;
|
|
|
|
gfx::Insets button_padding;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PaintAsActiveChanged();
|
|
|
|
|
|
|
|
void UpdateThemeValues();
|
|
|
|
|
|
|
|
enum class ButtonSide { kLeading, kTrailing };
|
|
|
|
|
2022-07-20 11:03:34 +00:00
|
|
|
ui::NavButtonProvider::FrameButtonDisplayType GetButtonTypeToSkip() const;
|
2022-01-26 21:59:09 +00:00
|
|
|
void UpdateButtonImages();
|
|
|
|
void LayoutButtons();
|
|
|
|
void LayoutButtonsOnSide(ButtonSide side,
|
|
|
|
gfx::Rect* remaining_content_bounds);
|
|
|
|
|
|
|
|
gfx::Rect GetTitlebarBounds() const;
|
|
|
|
gfx::Insets GetTitlebarContentInsets() const;
|
|
|
|
gfx::Rect GetTitlebarContentBounds() const;
|
|
|
|
|
|
|
|
gfx::Size SizeWithDecorations(gfx::Size size) const;
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<ui::NativeTheme> theme_;
|
2022-01-26 21:59:09 +00:00
|
|
|
ThemeValues theme_values_;
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
RAW_PTR_EXCLUSION views::Label* title_;
|
2022-01-26 21:59:09 +00:00
|
|
|
|
2022-07-20 11:03:34 +00:00
|
|
|
std::unique_ptr<ui::NavButtonProvider> nav_button_provider_;
|
2022-01-26 21:59:09 +00:00
|
|
|
std::array<NavButton, kNavButtonCount> nav_buttons_;
|
|
|
|
|
|
|
|
std::vector<views::FrameButton> leading_frame_buttons_;
|
|
|
|
std::vector<views::FrameButton> trailing_frame_buttons_;
|
|
|
|
|
|
|
|
bool host_supports_client_frame_shadow_ = false;
|
|
|
|
|
|
|
|
base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
|
|
|
|
native_theme_observer_{this};
|
2022-11-17 19:59:23 +00:00
|
|
|
base::ScopedObservation<ui::LinuxUi, ui::WindowButtonOrderObserver>
|
2022-01-26 21:59:09 +00:00
|
|
|
window_button_order_observer_{this};
|
|
|
|
|
|
|
|
base::CallbackListSubscription paint_as_active_changed_subscription_;
|
2022-10-27 16:37:04 +00:00
|
|
|
|
|
|
|
ui::WindowTiledEdges tiled_edges_;
|
2022-01-26 21:59:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_CLIENT_FRAME_VIEW_LINUX_H_
|