ccd4531bfb
* chore: bump chromium in DEPS to 117.0.5846.0 * chore: update patches * 4628901: Bump the macOS deployment target to 10.15 https://chromium-review.googlesource.com/c/chromium/src/+/4628901 * 4593350: [Private Network Access] Trigger Permission Prompt https://chromium-review.googlesource.com/c/chromium/src/+/4593350 * 4631011: Remove unlaunched "InstallReplacementAndroidApp" Platform App APIs https://chromium-review.googlesource.com/c/chromium/src/+/4631011 * chore: disable API deprecation warnings in NSKeyedArchiver * chore: update libcxx filenames * chore: bump chromium in DEPS to 117.0.5848.2 * chore: update feat_add_set_theme_source_to_allow_apps_to.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629743 No manual changes; patch succeeded with fuzz * chore: update process_singleton.patch Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4605398 Trivial manual patch adjustments to account for code shear. * chore: remove electron::BrowserContext::GetMediaDeviceIDSalt() Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4608130 upstream tldr: - content::BrowserContext::GetMediaDeviceIDSalt() - content::ContentBrowserClient::ArePersistentMediaDeviceIDsAllowed() + content::ContentBrowserClient::GetMediaDeviceIDSalt() This commit leaves ElectronBrowserContext::GetMediaDeviceIDSalt() in place (now non-virtual, non-override). It is now called by the new function ElectronBrowserClient::GetMediaDeviceIDSalt(). As a followup, we might want to consider using the new upstream media_device_salt::MediaDeviceSaltService and removing our electron::MediaDeviceIDSalt code. CC @MarshallOfSound for 2nd opinion since he has done the most work on MediaDeviceIDSalt and may have more context. * chore: fix iwyu breakage Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4629624 electron_browser_main_parts.cc uses ui::ColorProviderManager but didn't include it. Things worked anyway because we got it indirectly from content/public/browser/web_contents.h until 4629624. * chore: remove call to base::mac::IsAtLeastOS10_14 upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in IAP upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove obsolete API_AVAILABLE calls in electron_application_delegate upstream has bumped minimum version to 10.15 so this call is moot? * chore: remove broken-before-macOS-10.15 patch in mas_avoid_usage_of_private_macos_apis.patch Upstream has bumped minimum to macOS 10.15 * chore: remove @available(macOS 10.14) check Upstream minimum requirement for macOS is now 10.15 * chore: update patches * chore: bump chromium in DEPS to 117.0.5850.0 * chore: update patches * chore: bump chromium in DEPS to 117.0.5852.0 * chore: update patches * Move two params from NetworkContextParams to NetworkContextFilePaths. https://chromium-review.googlesource.com/c/chromium/src/+/4615930 * WebUSB: Add exclusionFilters to USBRequestDeviceOptions https://chromium-review.googlesource.com/c/chromium/src/+/4614682 * Convert /chrome/browser/ui to use ARC https://chromium-review.googlesource.com/c/chromium/src/+/4615920 * fixup! Bump the macOS deployment target to 10.15 * fixup! Bump the macOS deployment target to 10.15 * chore: update libcxx files * win: Remove 10Glass from Windows10Glass function and var names https://chromium-review.googlesource.com/c/chromium/src/+/4641314 * chore: revert 392e5f43 from chromium * Add an ExecutionContext to ScriptState https://chromium-review.googlesource.com/c/chromium/src/+/4609446 * fixup! Add an ExecutionContext to ScriptState * chore: fix header * Revert "chore: revert 392e5f43 from chromium" This reverts commit b7f782943e4ce83cae8cd35780d8d3618cf0772c. * fix: return correct min/max sizes in WinFrameView * fixup! Revert chore: revert 392e5f43 from chromium * fixup! Add an ExecutionContext to ScriptState * Revert "fixup! Revert chore: revert 392e5f43 from chromium" This reverts commit 7e2c7281abfc4f309255339fdba073d90a9ae3eb. * Revert "fix: return correct min/max sizes in WinFrameView" This reverts commit 3f418b1ab5155686730e087ae6cabe4a21b4bb61. * Revert "Revert "chore: revert 392e5f43 from chromium"" This reverts commit 56296d8b7c434147e032e3c3b08c0e371b6c27ba. --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
214 lines
6.7 KiB
C++
214 lines
6.7 KiB
C++
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Modified from chrome/browser/ui/views/frame/windows_caption_button.cc
|
|
|
|
#include "shell/browser/ui/views/win_caption_button.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/i18n/rtl.h"
|
|
#include "base/numerics/safe_conversions.h"
|
|
#include "base/win/windows_version.h"
|
|
#include "chrome/grit/theme_resources.h"
|
|
#include "shell/browser/ui/views/win_frame_view.h"
|
|
#include "shell/common/color_util.h"
|
|
#include "ui/base/metadata/metadata_impl_macros.h"
|
|
#include "ui/base/theme_provider.h"
|
|
#include "ui/gfx/animation/tween.h"
|
|
#include "ui/gfx/color_utils.h"
|
|
#include "ui/gfx/geometry/rect_conversions.h"
|
|
#include "ui/gfx/scoped_canvas.h"
|
|
|
|
namespace electron {
|
|
|
|
WinCaptionButton::WinCaptionButton(PressedCallback callback,
|
|
WinFrameView* frame_view,
|
|
ViewID button_type,
|
|
const std::u16string& accessible_name)
|
|
: views::Button(std::move(callback)),
|
|
frame_view_(frame_view),
|
|
icon_painter_(CreateIconPainter()),
|
|
button_type_(button_type) {
|
|
SetAnimateOnStateChange(true);
|
|
// Not focusable by default, only for accessibility.
|
|
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
|
|
SetAccessibleName(accessible_name);
|
|
}
|
|
|
|
WinCaptionButton::~WinCaptionButton() = default;
|
|
|
|
std::unique_ptr<WinIconPainter> WinCaptionButton::CreateIconPainter() {
|
|
if (base::win::GetVersion() >= base::win::Version::WIN11) {
|
|
return std::make_unique<Win11IconPainter>();
|
|
}
|
|
return std::make_unique<WinIconPainter>();
|
|
}
|
|
|
|
gfx::Size WinCaptionButton::CalculatePreferredSize() const {
|
|
// TODO(bsep): The sizes in this function are for 1x device scale and don't
|
|
// match Windows button sizes at hidpi.
|
|
|
|
return gfx::Size(base_width_ + GetBetweenButtonSpacing(), height_);
|
|
}
|
|
|
|
void WinCaptionButton::OnPaintBackground(gfx::Canvas* canvas) {
|
|
// Paint the background of the button (the semi-transparent rectangle that
|
|
// appears when you hover or press the button).
|
|
|
|
const SkColor bg_color = frame_view_->window()->overlay_button_color();
|
|
const SkAlpha theme_alpha = SkColorGetA(bg_color);
|
|
|
|
gfx::Rect bounds = GetContentsBounds();
|
|
bounds.Inset(gfx::Insets::TLBR(0, GetBetweenButtonSpacing(), 0, 0));
|
|
|
|
if (theme_alpha > 0)
|
|
canvas->FillRect(bounds, SkColorSetA(bg_color, theme_alpha));
|
|
|
|
SkColor base_color;
|
|
SkAlpha hovered_alpha, pressed_alpha;
|
|
if (button_type_ == VIEW_ID_CLOSE_BUTTON) {
|
|
base_color = SkColorSetRGB(0xE8, 0x11, 0x23);
|
|
hovered_alpha = SK_AlphaOPAQUE;
|
|
pressed_alpha = 0x98;
|
|
} else {
|
|
// Match the native buttons.
|
|
base_color = frame_view_->GetReadableFeatureColor(bg_color);
|
|
hovered_alpha = 0x1A;
|
|
pressed_alpha = 0x33;
|
|
|
|
if (theme_alpha > 0) {
|
|
// Theme buttons have slightly increased opacity to make them stand out
|
|
// against a visually-busy frame image.
|
|
constexpr float kAlphaScale = 1.3f;
|
|
hovered_alpha = base::ClampRound<SkAlpha>(hovered_alpha * kAlphaScale);
|
|
pressed_alpha = base::ClampRound<SkAlpha>(pressed_alpha * kAlphaScale);
|
|
}
|
|
}
|
|
|
|
SkAlpha alpha;
|
|
if (GetState() == STATE_PRESSED)
|
|
alpha = pressed_alpha;
|
|
else
|
|
alpha = gfx::Tween::IntValueBetween(hover_animation().GetCurrentValue(),
|
|
SK_AlphaTRANSPARENT, hovered_alpha);
|
|
canvas->FillRect(bounds, SkColorSetA(base_color, alpha));
|
|
}
|
|
|
|
void WinCaptionButton::PaintButtonContents(gfx::Canvas* canvas) {
|
|
PaintSymbol(canvas);
|
|
}
|
|
|
|
gfx::Size WinCaptionButton::GetSize() const {
|
|
return gfx::Size(base_width_, height_);
|
|
}
|
|
|
|
void WinCaptionButton::SetSize(gfx::Size size) {
|
|
int width = size.width();
|
|
int height = size.height();
|
|
|
|
if (width > 0)
|
|
base_width_ = width;
|
|
if (height > 0)
|
|
height_ = height;
|
|
|
|
InvalidateLayout();
|
|
}
|
|
|
|
int WinCaptionButton::GetBetweenButtonSpacing() const {
|
|
const int display_order_index = GetButtonDisplayOrderIndex();
|
|
return display_order_index == 0
|
|
? 0
|
|
: WindowFrameUtil::kWindowsCaptionButtonVisualSpacing;
|
|
}
|
|
|
|
int WinCaptionButton::GetButtonDisplayOrderIndex() const {
|
|
int button_display_order = 0;
|
|
switch (button_type_) {
|
|
case VIEW_ID_MINIMIZE_BUTTON:
|
|
button_display_order = 0;
|
|
break;
|
|
case VIEW_ID_MAXIMIZE_BUTTON:
|
|
case VIEW_ID_RESTORE_BUTTON:
|
|
button_display_order = 1;
|
|
break;
|
|
case VIEW_ID_CLOSE_BUTTON:
|
|
button_display_order = 2;
|
|
break;
|
|
default:
|
|
NOTREACHED();
|
|
return 0;
|
|
}
|
|
|
|
// Reverse the ordering if we're in RTL mode
|
|
if (base::i18n::IsRTL())
|
|
button_display_order = 2 - button_display_order;
|
|
|
|
return button_display_order;
|
|
}
|
|
|
|
void WinCaptionButton::PaintSymbol(gfx::Canvas* canvas) {
|
|
SkColor symbol_color = frame_view_->window()->overlay_symbol_color();
|
|
|
|
if (button_type_ == VIEW_ID_CLOSE_BUTTON &&
|
|
hover_animation().is_animating()) {
|
|
symbol_color = gfx::Tween::ColorValueBetween(
|
|
hover_animation().GetCurrentValue(), symbol_color, SK_ColorWHITE);
|
|
} else if (button_type_ == VIEW_ID_CLOSE_BUTTON &&
|
|
(GetState() == STATE_HOVERED || GetState() == STATE_PRESSED)) {
|
|
symbol_color = SK_ColorWHITE;
|
|
}
|
|
|
|
gfx::ScopedCanvas scoped_canvas(canvas);
|
|
const float scale = canvas->UndoDeviceScaleFactor();
|
|
|
|
const int symbol_size_pixels = std::round(10 * scale);
|
|
gfx::RectF bounds_rect(GetContentsBounds());
|
|
bounds_rect.Scale(scale);
|
|
gfx::Rect symbol_rect(gfx::ToEnclosingRect(bounds_rect));
|
|
symbol_rect.ClampToCenteredSize(
|
|
gfx::Size(symbol_size_pixels, symbol_size_pixels));
|
|
|
|
cc::PaintFlags flags;
|
|
flags.setAntiAlias(false);
|
|
flags.setColor(symbol_color);
|
|
flags.setStyle(cc::PaintFlags::kStroke_Style);
|
|
// Stroke width jumps up a pixel every time we reach a new integral scale.
|
|
const int stroke_width = std::floor(scale);
|
|
flags.setStrokeWidth(stroke_width);
|
|
|
|
switch (button_type_) {
|
|
case VIEW_ID_MINIMIZE_BUTTON: {
|
|
icon_painter_->PaintMinimizeIcon(canvas, symbol_rect, flags);
|
|
return;
|
|
}
|
|
|
|
case VIEW_ID_MAXIMIZE_BUTTON: {
|
|
icon_painter_->PaintMaximizeIcon(canvas, symbol_rect, flags);
|
|
return;
|
|
}
|
|
|
|
case VIEW_ID_RESTORE_BUTTON: {
|
|
icon_painter_->PaintRestoreIcon(canvas, symbol_rect, flags);
|
|
return;
|
|
}
|
|
|
|
case VIEW_ID_CLOSE_BUTTON: {
|
|
// The close button's X is surrounded by a "halo" of transparent pixels.
|
|
// When the X is white, the transparent pixels need to be a bit brighter
|
|
// to be visible.
|
|
const float stroke_halo =
|
|
stroke_width * (symbol_color == SK_ColorWHITE ? 0.1f : 0.05f);
|
|
flags.setStrokeWidth(stroke_width + stroke_halo);
|
|
|
|
icon_painter_->PaintCloseIcon(canvas, symbol_rect, flags);
|
|
return;
|
|
}
|
|
|
|
default:
|
|
NOTREACHED();
|
|
return;
|
|
}
|
|
}
|
|
} // namespace electron
|