2eb3bddb05
* chore: bump chromium in DEPS to 92.0.4500.2
* resolve conflicts
* update patches
* chore: cherry-pick 82434206f306 from chromium (#29060)
* fix patch
* chore: bump chromium in DEPS to 92.0.4501.0
* chore: bump chromium in DEPS to 92.0.4502.0
* chore: bump chromium in DEPS to 92.0.4503.0
* chore: update patches
* 2869869
: [Code Health] Refactor ListValue::Insert in gpu compositor
https://chromium-review.googlesource.com/c/chromium/src/+/2869869
* 2877924: Separate InkDropHost from InkDropHostView
https://chromium-review.googlesource.com/c/chromium/src/+/2877924
* chore: bump chromium in DEPS to 92.0.4504.0
* update patches
* Fixup for Separate InkDropHost from InkDropHostView
https://chromium-review.googlesource.com/c/chromium/src/+/2877924
* 2873469: Compute hashes of .pak files during the build, and check it at runtime.
https://chromium-review.googlesource.com/c/chromium/src/+/2873469
* 2874397: Remove flag to disable microtasks scope consistency checks
https://chromium-review.googlesource.com/c/v8/v8/+/2874397
* 2881471: Remove unneeded trace_event.h includes in headers.
https://chromium-review.googlesource.com/c/chromium/src/+/2881471
* 2844717: [Keyboard Tooltip] Rename RWHV*::SetTooltipText to UpdateTooltipUnderCursor
https://chromium-review.googlesource.com/c/chromium/src/+/2844717
* chore: bump chromium in DEPS to 92.0.4505.0
* chore: update patches
* 2883887: Retire ScopedObserver in /chrome/browser/predictors.
https://chromium-review.googlesource.com/c/chromium/src/+/2883887
* 2883694: Retire ScopedObserver in /chrome/browser.
https://chromium-review.googlesource.com/c/chromium/src/+/2883694
* fixup after merge
* fixup: Remove flag to disable microtasks scope consistency checks
* Temporarily disable setcallhandler-test.js nan test
This test should be renabled once https://github.com/electron/electron/pull/29028 lands
* Use gin_helper::MicrotasksScope instead of v8::MicrotasksScope
* chore: bump chromium in DEPS to 92.0.4506.0
* update patches
* Revert "update patches"
This reverts commit 333ec0d4c205bd3cbee28d2bc3d068871dbb900a.
* Revert "chore: bump chromium in DEPS to 92.0.4506.0"
This reverts commit 2bd52f8cd89b173c8b15a61d74fa7539cdbf574b.
* Fixup: Use gin_helper::MicrotasksScope instead of v8::MicrotasksScope
* Fixup: Use gin_helper::MicrotasksScope instead of v8::MicrotasksScope
Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
101 lines
3.3 KiB
C++
101 lines
3.3 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.
|
|
|
|
#include "shell/browser/ui/views/submenu_button.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "base/strings/string_util.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "ui/accessibility/ax_enums.mojom.h"
|
|
#include "ui/gfx/canvas.h"
|
|
#include "ui/gfx/color_utils.h"
|
|
#include "ui/gfx/text_utils.h"
|
|
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
|
|
#include "ui/views/animation/ink_drop_host_view.h"
|
|
#include "ui/views/animation/ink_drop_impl.h"
|
|
#include "ui/views/controls/button/label_button_border.h"
|
|
|
|
namespace electron {
|
|
|
|
SubmenuButton::SubmenuButton(PressedCallback callback,
|
|
const std::u16string& title,
|
|
const SkColor& background_color)
|
|
: views::MenuButton(callback, gfx::RemoveAccelerator(title)),
|
|
background_color_(background_color) {
|
|
#if defined(OS_LINUX)
|
|
// Dont' use native style border.
|
|
SetBorder(CreateDefaultBorder());
|
|
#endif
|
|
|
|
if (GetUnderlinePosition(title, &accelerator_, &underline_start_,
|
|
&underline_end_))
|
|
gfx::Canvas::SizeStringInt(GetText(), gfx::FontList(), &text_width_,
|
|
&text_height_, 0, 0);
|
|
|
|
ink_drop()->SetMode(views::InkDropHost::InkDropMode::ON);
|
|
ink_drop()->SetBaseColor(
|
|
color_utils::BlendTowardMaxContrast(background_color_, 0x81));
|
|
views::InkDrop::UseInkDropForFloodFillRipple(ink_drop(), false, true);
|
|
}
|
|
|
|
SubmenuButton::~SubmenuButton() = default;
|
|
|
|
void SubmenuButton::SetAcceleratorVisibility(bool visible) {
|
|
if (visible == show_underline_)
|
|
return;
|
|
|
|
show_underline_ = visible;
|
|
SchedulePaint();
|
|
}
|
|
|
|
void SubmenuButton::SetUnderlineColor(SkColor color) {
|
|
underline_color_ = color;
|
|
}
|
|
|
|
void SubmenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
|
|
node_data->SetName(GetAccessibleName());
|
|
node_data->role = ax::mojom::Role::kPopUpButton;
|
|
}
|
|
|
|
void SubmenuButton::PaintButtonContents(gfx::Canvas* canvas) {
|
|
views::MenuButton::PaintButtonContents(canvas);
|
|
|
|
if (show_underline_ && (underline_start_ != underline_end_)) {
|
|
float padding = (width() - text_width_) / 2;
|
|
float underline_height = (height() + text_height_) / 2 - 2;
|
|
canvas->DrawSharpLine(
|
|
gfx::PointF(underline_start_ + padding, underline_height),
|
|
gfx::PointF(underline_end_ + padding, underline_height),
|
|
underline_color_);
|
|
}
|
|
}
|
|
|
|
bool SubmenuButton::GetUnderlinePosition(const std::u16string& text,
|
|
char16_t* accelerator,
|
|
int* start,
|
|
int* end) const {
|
|
int pos, span;
|
|
std::u16string trimmed =
|
|
gfx::LocateAndRemoveAcceleratorChar(text, &pos, &span);
|
|
if (pos > -1 && span != 0) {
|
|
*accelerator = base::ToUpperASCII(trimmed[pos]);
|
|
GetCharacterPosition(trimmed, pos, start);
|
|
GetCharacterPosition(trimmed, pos + span, end);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void SubmenuButton::GetCharacterPosition(const std::u16string& text,
|
|
int index,
|
|
int* pos) const {
|
|
int height = 0;
|
|
gfx::Canvas::SizeStringInt(text.substr(0, index), gfx::FontList(), pos,
|
|
&height, 0, 0);
|
|
}
|
|
|
|
} // namespace electron
|