refactor: add NativeWindowViews::SetTitleBarOverlay()
(#47126)
* refactor: move SetTitleBarOverlay() impl to NativeWindowViews * refactor: make NativeWindowViews::set_overlay_button_color() private refactor: make NativeWindowViews::set_overlay_symbol_color() private refactor: make NativeWindow::set_titlebar_overlay_height() protected * refactor: simplify downcasting in NativeWindowViews::SetTitleBarOverlay()
This commit is contained in:
parent
d426667a01
commit
687e50b4f3
4 changed files with 73 additions and 63 deletions
|
@ -1093,64 +1093,8 @@ bool BaseWindow::IsSnapped() const {
|
|||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
|
||||
void BaseWindow::SetTitleBarOverlay(const gin_helper::Dictionary& options,
|
||||
gin_helper::Arguments* args) {
|
||||
// Ensure WCO is already enabled on this window
|
||||
if (!window_->IsWindowControlsOverlayEnabled()) {
|
||||
args->ThrowError("Titlebar overlay is not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* window = static_cast<NativeWindowViews*>(window_.get());
|
||||
bool updated = false;
|
||||
|
||||
// Check and update the button color
|
||||
std::string btn_color;
|
||||
if (options.Get(options::kOverlayButtonColor, &btn_color)) {
|
||||
// Parse the string as a CSS color
|
||||
SkColor color;
|
||||
if (!content::ParseCssColorString(btn_color, &color)) {
|
||||
args->ThrowError("Could not parse color as CSS color");
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the view
|
||||
window->set_overlay_button_color(color);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// Check and update the symbol color
|
||||
std::string symbol_color;
|
||||
if (options.Get(options::kOverlaySymbolColor, &symbol_color)) {
|
||||
// Parse the string as a CSS color
|
||||
SkColor color;
|
||||
if (!content::ParseCssColorString(symbol_color, &color)) {
|
||||
args->ThrowError("Could not parse symbol color as CSS color");
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the view
|
||||
window->set_overlay_symbol_color(color);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// Check and update the height
|
||||
int height = 0;
|
||||
if (options.Get(options::kOverlayHeight, &height)) {
|
||||
window->set_titlebar_overlay_height(height);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (!updated)
|
||||
return;
|
||||
|
||||
// If anything was updated, ensure the overlay is repainted.
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
auto* frame_view = static_cast<WinFrameView*>(
|
||||
window->widget()->non_client_view()->frame_view());
|
||||
#else
|
||||
auto* frame_view = static_cast<OpaqueFrameView*>(
|
||||
window->widget()->non_client_view()->frame_view());
|
||||
#endif
|
||||
frame_view->InvalidateCaptionButtons();
|
||||
static_cast<NativeWindowViews*>(window_.get())
|
||||
->SetTitleBarOverlay(options, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue