* chore: bump chromium in DEPS to 142.0.7432.2 * chore: bump chromium in DEPS to 142.0.7434.1 * chore: bump chromium in DEPS to 142.0.7436.1 * chore: bump chromium in DEPS to 142.0.7438.1 * chore: bump chromium in DEPS to 142.0.7440.1 * chore: bump chromium in DEPS to 142.0.7442.1 * chore: bump chromium in DEPS to 142.0.7444.1 * chore: bump chromium in DEPS to 142.0.7444.6 * chore: bump chromium in DEPS to 142.0.7444.3 * 6973697: Use type tags for data stored in V8 internal fields https://chromium-review.googlesource.com/c/chromium/src/+/6973697 * chore: update patches * chore: update filenames.libcxx.gni * fix: parse macOS SDK version across line break https://chromium-review.googlesource.com/c/chromium/src/+/6980166 (cherry picked from commit 2bcbb33de04fa13e7c923b2420f89c3846f5988b) * fix: replace v8::Object::SetPrototype() usage https://chromium-review.googlesource.com/c/v8/v8/+/6983465 https://github.com/nodejs/node/pull/55453 (cherry picked from commit c31b9ed5ac84bbd111c72273d9334af6c50ed374) * fix: replace additional usages of SetPrototype https://chromium-review.googlesource.com/c/v8/v8/+/6983465 (cherry picked from commit bf151e9d28520c7dd74cba62240acbcaaab5433d) * fixup! fix: replace additional usages of SetPrototype https://chromium-review.googlesource.com/c/v8/v8/+/6983465 (cherry picked from commit f4434755b82b098e4d83d42bab26f183b6824f99) * build: use macos 15 minimum https://chromium-review.googlesource.com/c/chromium/src/+/6980166 (cherry picked from commit 4d2b5d7b2cf9a1786cdb1a77bf73e4ad0d3e45d1) * fixup! build: use macos 15 minimum https://chromium-review.googlesource.com/c/chromium/src/+/6980166 (cherry picked from commit 94bb41a66330dcaf6b92c80cfefd72759405793d) * ci: ignore missing dir for strip_universal_deep (cherry picked from commit 634963f171bc5f6050151f76973e7ffbab0e00cf) * chore: update patches * chore: update patches * chore: bump chromium in DEPS to 142.0.7444.23 * fix: disable C++ modules in electron_lib builds https://chromium-review.googlesource.com/c/chromium/src/+/6950738 (cherry picked from commit 6207c79aecae04675b1e258ec14025c3ddfdf270) * Revert "build: use macos 15 minimum" This reverts commit 2fc12d6acc1b24f3cbd0adb03122bf6b21eb14b9. Initially this change was made to test if it fixes libcxx compilation issues. As that's now resolved by disabling libcxx modules, this can be reverted. (cherry picked from commit ad52007d5baffc3da65c0a994943f25da0c3f1c2) * fix: js2c compilation failure https://chromium-review.googlesource.com/c/chromium/src/+/6950738 See patch description explaining MacOS 26 SDK headers incompatibility. (cherry picked from commit 39e2470875cdbf20b86c30ee2c5caa8845465434) * fix: disable C++ modules in libnode builds (cherry picked from commit fd0a7b61a151c92729da41eba63fb7ee5b0beebc) * fixup! fix: replace v8::Object::SetPrototype() usage https://chromium-review.googlesource.com/c/v8/v8/+/6983465 https://github.com/nodejs/node/pull/55453 (cherry picked from commit 2f52159b71ee4aa779dfd3e3050f3b09c2664c36) * build: switch to macos-15 runner build/mac/find_sdk.py now requires macOS 15 SDK as a minimum version. The macos 15 runners default to an Xcode using the 15 SDK and removes older versions. (cherry picked from commit e368703f24577e73d904c684a0b4ae53bacfaef2) * chore: update patches * fix: partially revert is_headless_mode removal https://chromium-review.googlesource.com/c/chromium/src/+/6955633 This patch should likely be reworked. For now, this partially reverts the removal of a required class property to restore behavior. (cherry picked from commit aff3bf9a244608863bc96b3e2aef911158b29574) * 6938086: Rename native_widget_types.h -> native_ui_types.h | https://chromium-review.googlesource.com/c/chromium/src/+/6938086 (cherry picked from commit c95ac7bf2b1eda493167b8e36c59d70d86d51429) * 6973697: Use type tags for data stored in V8 internal fields https://chromium-review.googlesource.com/c/chromium/src/+/6973697 * fixup! fix: check new forced colors enum value https://chromium-review.googlesource.com/c/chromium/src/+/6944403 (cherry picked from commit 0829c74b2fbcdf03ca462b4b0b76efd727d3d891) * fix: check new forced colors enum value https://chromium-review.googlesource.com/c/chromium/src/+/6944403 (cherry picked from commit d5858798074719d19d041fa291c3fd1af8d17f5d) * feat: add new memory-eviction exit reason https://chromium-review.googlesource.com/c/chromium/src/+/6991933 (cherry picked from commit 6e63197a2292aece65cd52b7b849d3ff3d10bb90) * fix: views::NonClientFrameView -> views::FrameView https://chromium-review.googlesource.com/c/chromium/src/+/7005027 https://chromium-review.googlesource.com/c/chromium/src/+/6966937 (cherry picked from commit 1e86b6ddfb2d19b5bfe30e7539f0a377ffa907ab) * fix: migrate NetworkConditions -> MatchedNetworkConditions https://chromium-review.googlesource.com/c/chromium/src/+/6827307 (cherry picked from commit 97100ac1682053d3447e63ed5f03dc2d9938e6ca) * fix: provide DeviceEmulationCacheBehavior param https://chromium-review.googlesource.com/c/chromium/src/+/6965238 (cherry picked from commit f9a08c53846ab269c57c14eae6b1c03b163fb30c) * fix: add missing image_skia include https://chromium-review.googlesource.com/c/chromium/src/+/6986762 (cherry picked from commit dd5eaf03fd7fbfd49afbe3259c5bf036be566bd9) * fixup! fix: add missing image_skia include https://chromium-review.googlesource.com/c/chromium/src/+/6986762 (cherry picked from commit 249c4d4de1df4d1588d6fa6fcf5f33b43a6c0f62) * 6948286: [wasm-imported-strings] Drop feature flag https://chromium-review.googlesource.com/c/v8/v8/+/6948286 * fix: disable protocol handler DCHECK https://chromium-review.googlesource.com/c/chromium/src/+/6727594 Ignore the extension custom protocol handler registry DCHECK until we invest in supporting it. Replacing this DCHECK seems harmless and will unblock the roll. (cherry picked from commit 019d3f0b09aeff8aed7991d9669a4ba7f265808b) * 6986762: Remove some includes of //ui/gfx/image/image_skia.h https: //chromium-review.googlesource.com/c/chromium/src/+/6986762 * fixup! fix: migrate NetworkConditions -> MatchedNetworkConditions https://chromium-review.googlesource.com/c/chromium/src/+/6827307 (cherry picked from commit a8f67f1ac3f8b07354d9457be9addf242ff70000) * fixup: 6986762: Remove some includes of //ui/gfx/image/image_skia.h s * fix: replace deprecated usage of SetPrototype https://chromium-review.googlesource.com/c/v8/v8/+/6983465 (cherry picked from commit 5435d87b40c15316bc8828fbc197be647b39b7bb) * chore: restore electron embedder data tag patch Co-Authored-By: Sam Maddock <sam@samuelmaddock.com> * chore: update patches --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> Co-authored-by: Alice Zhao <alicelovescake@anthropic.com> Co-authored-by: Sam Maddock <sam@samuelmaddock.com>
288 lines
11 KiB
C++
288 lines
11 KiB
C++
// Copyright (c) 2014 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
//
|
|
// Portions of this file are sourced from
|
|
// chrome/browser/ui/views/frame/glass_browser_frame_view.cc,
|
|
// Copyright (c) 2012 The Chromium Authors,
|
|
// which is governed by a BSD-style license
|
|
|
|
#include "shell/browser/ui/views/win_frame_view.h"
|
|
|
|
#include <dwmapi.h>
|
|
#include <memory>
|
|
|
|
#include "shell/browser/native_window_views.h"
|
|
#include "shell/browser/ui/views/win_caption_button_container.h"
|
|
#include "ui/base/metadata/metadata_impl_macros.h"
|
|
#include "ui/base/win/hwnd_metrics.h"
|
|
#include "ui/display/win/dpi.h"
|
|
#include "ui/display/win/screen_win.h"
|
|
#include "ui/gfx/geometry/dip_util.h"
|
|
#include "ui/views/background.h"
|
|
#include "ui/views/widget/widget.h"
|
|
#include "ui/views/win/hwnd_util.h"
|
|
|
|
namespace electron {
|
|
|
|
WinFrameView::WinFrameView() = default;
|
|
|
|
WinFrameView::~WinFrameView() = default;
|
|
|
|
void WinFrameView::Init(NativeWindowViews* window, views::Widget* frame) {
|
|
window_ = window;
|
|
frame_ = frame;
|
|
|
|
if (window->IsWindowControlsOverlayEnabled()) {
|
|
caption_button_container_ =
|
|
AddChildView(std::make_unique<WinCaptionButtonContainer>(this));
|
|
}
|
|
}
|
|
|
|
SkColor WinFrameView::GetReadableFeatureColor(SkColor background_color) {
|
|
// color_utils::GetColorWithMaxContrast()/IsDark() aren't used here because
|
|
// they switch based on the Chrome light/dark endpoints, while we want to use
|
|
// the system native behavior below.
|
|
const auto windows_luma = [](SkColor c) {
|
|
return 0.25f * SkColorGetR(c) + 0.625f * SkColorGetG(c) +
|
|
0.125f * SkColorGetB(c);
|
|
};
|
|
return windows_luma(background_color) <= 128.0f ? SK_ColorWHITE
|
|
: SK_ColorBLACK;
|
|
}
|
|
|
|
void WinFrameView::InvalidateCaptionButtons() {
|
|
if (!caption_button_container_)
|
|
return;
|
|
|
|
caption_button_container_->UpdateBackground();
|
|
caption_button_container_->InvalidateLayout();
|
|
caption_button_container_->SchedulePaint();
|
|
}
|
|
|
|
gfx::Rect WinFrameView::GetWindowBoundsForClientBounds(
|
|
const gfx::Rect& client_bounds) const {
|
|
return views::GetWindowBoundsForClientBounds(
|
|
static_cast<views::View*>(const_cast<WinFrameView*>(this)),
|
|
client_bounds);
|
|
}
|
|
|
|
int WinFrameView::FrameBorderThickness() const {
|
|
if (frame()->IsFullscreen() || IsMaximized())
|
|
return 0;
|
|
|
|
return display::win::GetScreenWin()->GetSystemMetricsInDIP(SM_CXSIZEFRAME);
|
|
}
|
|
|
|
views::View* WinFrameView::TargetForRect(views::View* root,
|
|
const gfx::Rect& rect) {
|
|
if (NonClientHitTest(rect.origin()) != HTCLIENT) {
|
|
// Custom system titlebar returns non HTCLIENT value, however event should
|
|
// be handled by the view, not by the system, because there are no system
|
|
// buttons underneath.
|
|
if (!window()->IsWindowControlsOverlayEnabled())
|
|
return this;
|
|
|
|
auto local_point = rect.origin();
|
|
ConvertPointToTarget(parent(), caption_button_container_, &local_point);
|
|
if (!caption_button_container_->HitTestPoint(local_point))
|
|
return this;
|
|
}
|
|
|
|
return FrameView::TargetForRect(root, rect);
|
|
}
|
|
|
|
int WinFrameView::NonClientHitTest(const gfx::Point& point) {
|
|
if (window()->has_frame())
|
|
return frame_->client_view()->NonClientHitTest(point);
|
|
|
|
if (window()->IsWindowControlsOverlayEnabled()) {
|
|
// See if the point is within any of the window controls.
|
|
if (caption_button_container_) {
|
|
gfx::Point local_point = point;
|
|
|
|
ConvertPointToTarget(parent(), caption_button_container_, &local_point);
|
|
if (caption_button_container_->HitTestPoint(local_point)) {
|
|
const int hit_test_result =
|
|
caption_button_container_->NonClientHitTest(local_point);
|
|
if (hit_test_result != HTNOWHERE)
|
|
return hit_test_result;
|
|
}
|
|
}
|
|
|
|
// On Windows 8+, the caption buttons are almost butted up to the top right
|
|
// corner of the window. This code ensures the mouse isn't set to a size
|
|
// cursor while hovering over the caption buttons, thus giving the incorrect
|
|
// impression that the user can resize the window.
|
|
RECT button_bounds = {0};
|
|
if (SUCCEEDED(DwmGetWindowAttribute(
|
|
views::HWNDForWidget(frame()), DWMWA_CAPTION_BUTTON_BOUNDS,
|
|
&button_bounds, sizeof(button_bounds)))) {
|
|
gfx::RectF button_bounds_in_dips = gfx::ConvertRectToDips(
|
|
gfx::Rect(button_bounds), display::win::GetDPIScale());
|
|
// TODO(crbug.com/1131681): GetMirroredRect() requires an integer rect,
|
|
// but the size in DIPs may not be an integer with a fractional device
|
|
// scale factor. If we want to keep using integers, the choice to use
|
|
// ToFlooredRectDeprecated() seems to be doing the wrong thing given the
|
|
// comment below about insetting 1 DIP instead of 1 physical pixel. We
|
|
// should probably use ToEnclosedRect() and then we could have inset 1
|
|
// physical pixel here.
|
|
gfx::Rect buttons =
|
|
GetMirroredRect(gfx::ToFlooredRectDeprecated(button_bounds_in_dips));
|
|
|
|
// There is a small one-pixel strip right above the caption buttons in
|
|
// which the resize border "peeks" through.
|
|
constexpr int kCaptionButtonTopInset = 1;
|
|
// The sizing region at the window edge above the caption buttons is
|
|
// 1 px regardless of scale factor. If we inset by 1 before converting
|
|
// to DIPs, the precision loss might eliminate this region entirely. The
|
|
// best we can do is to inset after conversion. This guarantees we'll
|
|
// show the resize cursor when resizing is possible. The cost of which
|
|
// is also maybe showing it over the portion of the DIP that isn't the
|
|
// outermost pixel.
|
|
buttons.Inset(gfx::Insets::TLBR(0, kCaptionButtonTopInset, 0, 0));
|
|
if (buttons.Contains(point))
|
|
return HTNOWHERE;
|
|
}
|
|
|
|
int top_border_thickness = FrameTopBorderThickness(false);
|
|
// At the window corners the resize area is not actually bigger, but the 16
|
|
// pixels at the end of the top and bottom edges trigger diagonal resizing.
|
|
constexpr int kResizeCornerWidth = 16;
|
|
int window_component = GetHTComponentForFrame(
|
|
point, gfx::Insets::TLBR(top_border_thickness, 0, 0, 0),
|
|
top_border_thickness, kResizeCornerWidth - FrameBorderThickness(),
|
|
frame()->widget_delegate()->CanResize());
|
|
if (window_component != HTNOWHERE)
|
|
return window_component;
|
|
}
|
|
|
|
// Use the parent class's hittest last
|
|
return FramelessView::NonClientHitTest(point);
|
|
}
|
|
|
|
bool WinFrameView::IsMaximized() const {
|
|
return frame()->IsMaximized();
|
|
}
|
|
|
|
void WinFrameView::Layout(PassKey) {
|
|
LayoutCaptionButtons();
|
|
if (window()->IsWindowControlsOverlayEnabled()) {
|
|
LayoutWindowControlsOverlay();
|
|
}
|
|
LayoutSuperclass<FrameView>(this);
|
|
}
|
|
|
|
int WinFrameView::FrameTopBorderThickness(bool restored) const {
|
|
// Mouse and touch locations are floored but GetSystemMetricsInDIP is rounded,
|
|
// so we need to floor instead or else the difference will cause the hittest
|
|
// to fail when it ought to succeed.
|
|
return std::floor(
|
|
FrameTopBorderThicknessPx(restored) /
|
|
display::win::GetScreenWin()->GetScaleFactorForHWND(HWNDForView(this)));
|
|
}
|
|
|
|
int WinFrameView::FrameTopBorderThicknessPx(bool restored) const {
|
|
// Distinct from FrameBorderThickness() because we can't inset the top
|
|
// border, otherwise Windows will give us a standard titlebar.
|
|
// For maximized windows this is not true, and the top border must be
|
|
// inset in order to avoid overlapping the monitor above.
|
|
|
|
// See comments in BrowserDesktopWindowTreeHostWin::GetClientAreaInsets().
|
|
const bool needs_no_border =
|
|
(window()->IsWindowControlsOverlayEnabled() && frame()->IsMaximized()) ||
|
|
frame()->IsFullscreen();
|
|
if (needs_no_border && !restored)
|
|
return 0;
|
|
|
|
// Note that this method assumes an equal resize handle thickness on all
|
|
// sides of the window.
|
|
// TODO(dfried): Consider having it return a gfx::Insets object instead.
|
|
return ui::GetFrameThicknessFromWindow(HWNDForView(this),
|
|
MONITOR_DEFAULTTONEAREST);
|
|
}
|
|
|
|
int WinFrameView::TitlebarMaximizedVisualHeight() const {
|
|
int maximized_height =
|
|
display::win::GetScreenWin()->GetSystemMetricsInDIP(SM_CYCAPTION);
|
|
return maximized_height;
|
|
}
|
|
|
|
// NOTE(@mlaurencin): Usage of IsWebUITabStrip simplified out from Chromium
|
|
int WinFrameView::TitlebarHeight(int custom_height) const {
|
|
if (frame()->IsFullscreen() && !IsMaximized())
|
|
return 0;
|
|
|
|
int height = TitlebarMaximizedVisualHeight() +
|
|
FrameTopBorderThickness(false) - WindowTopY();
|
|
if (custom_height > TitlebarMaximizedVisualHeight())
|
|
height = custom_height - WindowTopY();
|
|
|
|
return height;
|
|
}
|
|
|
|
// NOTE(@mlaurencin): Usage of IsWebUITabStrip simplified out from Chromium
|
|
int WinFrameView::WindowTopY() const {
|
|
// The window top is SM_CYSIZEFRAME pixels when maximized (see the comment in
|
|
// FrameTopBorderThickness()) and floor(system dsf) pixels when restored.
|
|
// Unfortunately we can't represent either of those at hidpi without using
|
|
// non-integral dips, so we return the closest reasonable values instead.
|
|
if (IsMaximized())
|
|
return FrameTopBorderThickness(false);
|
|
|
|
return 1;
|
|
}
|
|
|
|
void WinFrameView::LayoutCaptionButtons() {
|
|
if (!caption_button_container_)
|
|
return;
|
|
|
|
// Non-custom system titlebar already contains caption buttons.
|
|
if (!window()->IsWindowControlsOverlayEnabled()) {
|
|
caption_button_container_->SetVisible(false);
|
|
return;
|
|
}
|
|
|
|
caption_button_container_->SetVisible(true);
|
|
const gfx::Size preferred_size =
|
|
caption_button_container_->GetPreferredSize();
|
|
|
|
int custom_height = window()->titlebar_overlay_height();
|
|
int height = TitlebarHeight(custom_height);
|
|
|
|
// TODO(mlaurencin): This -1 creates a 1 pixel margin between the right
|
|
// edge of the button container and the edge of the window, allowing for this
|
|
// edge portion to return the correct hit test and be manually resized
|
|
// properly. Alternatives can be explored, but the differences in view
|
|
// structures between Electron and Chromium may result in this as the best
|
|
// option.
|
|
int variable_width =
|
|
IsMaximized() ? preferred_size.width() : preferred_size.width() - 1;
|
|
caption_button_container_->SetBounds(width() - preferred_size.width(),
|
|
WindowTopY(), variable_width, height);
|
|
|
|
// Needed for heights larger than default
|
|
caption_button_container_->SetButtonSize(gfx::Size(0, height));
|
|
}
|
|
|
|
void WinFrameView::LayoutWindowControlsOverlay() {
|
|
int overlay_height = window()->titlebar_overlay_height();
|
|
if (overlay_height == 0) {
|
|
// Accounting for the 1 pixel margin at the top of the button container
|
|
overlay_height = IsMaximized()
|
|
? caption_button_container_->size().height()
|
|
: caption_button_container_->size().height() + 1;
|
|
}
|
|
int overlay_width = caption_button_container_->size().width();
|
|
int bounding_rect_width = width() - overlay_width;
|
|
auto bounding_rect =
|
|
GetMirroredRect(gfx::Rect(0, 0, bounding_rect_width, overlay_height));
|
|
|
|
window()->SetWindowControlsOverlayRect(bounding_rect);
|
|
window()->NotifyLayoutWindowControlsOverlay();
|
|
}
|
|
|
|
BEGIN_METADATA(WinFrameView)
|
|
END_METADATA
|
|
|
|
} // namespace electron
|