|
10 | 10 | #include "content/browser/web_contents/web_contents_impl.h" // nogncheck |
11 | 11 | #include "content/public/browser/render_process_host.h" |
12 | 12 | #include "content/public/browser/render_view_host.h" |
| 13 | +#include "content/public/common/color_parser.h" |
13 | 14 | #include "shell/browser/api/electron_api_web_contents_view.h" |
14 | 15 | #include "shell/browser/browser.h" |
15 | 16 | #include "shell/browser/native_browser_view.h" |
|
24 | 25 | #include "shell/common/options_switches.h" |
25 | 26 | #include "ui/gl/gpu_switching_manager.h" |
26 | 27 |
|
| 28 | +#if defined(TOOLKIT_VIEWS) |
| 29 | +#include "shell/browser/native_window_views.h" |
| 30 | +#endif |
| 31 | + |
| 32 | +#if BUILDFLAG(IS_WIN) |
| 33 | +#include "shell/browser/ui/views/win_frame_view.h" |
| 34 | +#endif |
| 35 | + |
27 | 36 | namespace electron { |
28 | 37 |
|
29 | 38 | namespace api { |
@@ -466,6 +475,65 @@ v8::Local<v8::Value> BrowserWindow::GetWebContents(v8::Isolate* isolate) { |
466 | 475 | return v8::Local<v8::Value>::New(isolate, web_contents_); |
467 | 476 | } |
468 | 477 |
|
| 478 | +#if BUILDFLAG(IS_WIN) |
| 479 | +void BrowserWindow::SetTitleBarOverlay(const gin_helper::Dictionary& options, |
| 480 | + gin_helper::Arguments* args) { |
| 481 | + // Ensure WCO is already enabled on this window |
| 482 | + if (!window_->titlebar_overlay_enabled()) { |
| 483 | + args->ThrowError("Titlebar overlay is not enabled"); |
| 484 | + return; |
| 485 | + } |
| 486 | + |
| 487 | + auto* window = static_cast<NativeWindowViews*>(window_.get()); |
| 488 | + bool updated = false; |
| 489 | + |
| 490 | + // Check and update the button color |
| 491 | + std::string btn_color; |
| 492 | + if (options.Get(options::kOverlayButtonColor, &btn_color)) { |
| 493 | + // Parse the string as a CSS color |
| 494 | + SkColor color; |
| 495 | + if (!content::ParseCssColorString(btn_color, &color)) { |
| 496 | + args->ThrowError("Could not parse color as CSS color"); |
| 497 | + return; |
| 498 | + } |
| 499 | + |
| 500 | + // Update the view |
| 501 | + window->set_overlay_button_color(color); |
| 502 | + updated = true; |
| 503 | + } |
| 504 | + |
| 505 | + // Check and update the symbol color |
| 506 | + std::string symbol_color; |
| 507 | + if (options.Get(options::kOverlaySymbolColor, &symbol_color)) { |
| 508 | + // Parse the string as a CSS color |
| 509 | + SkColor color; |
| 510 | + if (!content::ParseCssColorString(symbol_color, &color)) { |
| 511 | + args->ThrowError("Could not parse symbol color as CSS color"); |
| 512 | + return; |
| 513 | + } |
| 514 | + |
| 515 | + // Update the view |
| 516 | + window->set_overlay_symbol_color(color); |
| 517 | + updated = true; |
| 518 | + } |
| 519 | + |
| 520 | + // Check and update the height |
| 521 | + int height = 0; |
| 522 | + if (options.Get(options::kOverlayHeight, &height)) { |
| 523 | + window->set_titlebar_overlay_height(height); |
| 524 | + updated = true; |
| 525 | + } |
| 526 | + |
| 527 | + // If anything was updated, invalidate the layout and schedule a paint of the |
| 528 | + // window's frame view |
| 529 | + if (updated) { |
| 530 | + auto* frame_view = static_cast<WinFrameView*>( |
| 531 | + window->widget()->non_client_view()->frame_view()); |
| 532 | + frame_view->InvalidateCaptionButtons(); |
| 533 | + } |
| 534 | +} |
| 535 | +#endif |
| 536 | + |
469 | 537 | void BrowserWindow::ScheduleUnresponsiveEvent(int ms) { |
470 | 538 | if (!window_unresponsive_closure_.IsCancelled()) |
471 | 539 | return; |
@@ -524,6 +592,9 @@ void BrowserWindow::BuildPrototype(v8::Isolate* isolate, |
524 | 592 | .SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView) |
525 | 593 | .SetMethod("blurWebView", &BrowserWindow::BlurWebView) |
526 | 594 | .SetMethod("isWebViewFocused", &BrowserWindow::IsWebViewFocused) |
| 595 | +#if BUILDFLAG(IS_WIN) |
| 596 | + .SetMethod("setTitleBarOverlay", &BrowserWindow::SetTitleBarOverlay) |
| 597 | +#endif |
527 | 598 | .SetProperty("webContents", &BrowserWindow::GetWebContents); |
528 | 599 | } |
529 | 600 |
|
|
0 commit comments