Skip to content

Commit abb7a81

Browse files
refactor: setBounds, setScale, setOpacity with animation
1 parent 57e74ef commit abb7a81

23 files changed

+579
-330
lines changed

filenames.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ filenames = {
226226
"shell/browser/ui/native_scroll_view_views.cc",
227227
"shell/browser/ui/native_view_views.cc",
228228
"shell/browser/ui/native_wrapper_browser_view_views.cc",
229+
"shell/browser/ui/view_utils_views.cc",
229230
"shell/browser/ui/views/autofill_popup_view.cc",
230231
"shell/browser/ui/views/autofill_popup_view.h",
231232
"shell/browser/ui/views/electron_views_delegate.cc",
@@ -538,6 +539,7 @@ filenames = {
538539
"shell/browser/ui/tray_icon.cc",
539540
"shell/browser/ui/tray_icon.h",
540541
"shell/browser/ui/tray_icon_observer.h",
542+
"shell/browser/ui/view_utils.cc",
541543
"shell/browser/ui/view_utils.h",
542544
"shell/browser/ui/webui/accessibility_ui.cc",
543545
"shell/browser/ui/webui/accessibility_ui.h",

shell/browser/api/electron_api_base_view.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool BaseView::IsClickThrough() const {
257257
}
258258

259259
void BaseView::SetBounds(const gfx::Rect& bounds, gin::Arguments* args) {
260-
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
260+
BoundsAnimationOptions options;
261261
args->GetNext(&options);
262262
view_->SetBounds(bounds, options);
263263
}
@@ -393,7 +393,7 @@ void BaseView::ResetScaling() {
393393
view_->ResetScaling();
394394
}
395395

396-
void BaseView::SetScale(const gin_helper::Dictionary& options) {
396+
void BaseView::SetScale(const ScaleAnimationOptions& options) {
397397
view_->SetScale(options);
398398
}
399399

@@ -406,7 +406,7 @@ float BaseView::GetScaleY() {
406406
}
407407

408408
void BaseView::SetOpacity(const double opacity, gin::Arguments* args) {
409-
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
409+
AnimationOptions options;
410410
args->GetNext(&options);
411411
view_->SetOpacity(opacity, options);
412412
}

shell/browser/api/electron_api_base_view.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66

77
#include "shell/browser/ui/native_view.h"
8+
#include "shell/browser/ui/view_utils.h"
89
#include "shell/common/gin_helper/error_thrower.h"
910
#include "shell/common/gin_helper/trackable_object.h"
1011

@@ -109,7 +110,7 @@ class BaseView : public gin_helper::TrackableObject<BaseView>,
109110
void SetRoundedCorners(const NativeView::RoundedCornersOptions& options);
110111
void SetClippingInsets(const NativeView::ClippingInsetOptions& options);
111112
void ResetScaling();
112-
void SetScale(const gin_helper::Dictionary& options);
113+
void SetScale(const ScaleAnimationOptions& options);
113114
float GetScaleX();
114115
float GetScaleY();
115116
void SetOpacity(const double opacity, gin::Arguments* args);

shell/browser/api/electron_api_browser_view.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void BrowserView::SetAutoResize(AutoResizeFlags flags) {
161161
}
162162

163163
void BrowserView::SetBounds(const gfx::Rect& bounds, gin::Arguments* args) {
164-
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
164+
BoundsAnimationOptions options;
165165
args->GetNext(&options);
166166
view_->SetBounds(bounds, options);
167167
}
@@ -205,7 +205,7 @@ void BrowserView::ResetScaling() {
205205
view_->ResetScaling();
206206
}
207207

208-
void BrowserView::SetScale(const gin_helper::Dictionary& options) {
208+
void BrowserView::SetScale(const ScaleAnimationOptions& options) {
209209
view_->SetScale(options);
210210
}
211211

@@ -218,7 +218,7 @@ float BrowserView::GetScaleY() {
218218
}
219219

220220
void BrowserView::SetOpacity(const double opacity, gin::Arguments* args) {
221-
gin::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate());
221+
AnimationOptions options;
222222
args->GetNext(&options);
223223
view_->SetOpacity(opacity, options);
224224
}

shell/browser/api/electron_api_browser_view.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "shell/browser/native_browser_view.h"
1717
#include "shell/browser/native_window.h"
1818
#include "shell/browser/ui/native_wrapper_browser_view.h"
19+
#include "shell/browser/ui/view_utils.h"
1920
#include "shell/common/api/api.mojom.h"
2021
#include "shell/common/gin_helper/constructible.h"
2122
#include "shell/common/gin_helper/error_thrower.h"
@@ -89,7 +90,7 @@ class BrowserView : public gin::Wrappable<BrowserView>,
8990
void SetViewBounds(const gfx::Rect& bounds);
9091
gfx::Rect GetViewBounds();
9192
void ResetScaling();
92-
void SetScale(const gin_helper::Dictionary& options);
93+
void SetScale(const ScaleAnimationOptions& options);
9394
float GetScaleX();
9495
float GetScaleY();
9596
void SetOpacity(const double opacity, gin::Arguments* args);

shell/browser/api/electron_api_scroll_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ gfx::Point ScrollView::GetMaximumScrollPosition() const {
183183
}
184184

185185
void ScrollView::ScrollToPoint(gfx::Point point,
186-
const gin_helper::Dictionary& options) {
186+
const AnimationOptions& options) {
187187
scroll_->ScrollToPoint(point, options);
188188
}
189189

190190
void ScrollView::ScrollPointToCenter(gfx::Point point,
191-
const gin_helper::Dictionary& options) {
191+
const AnimationOptions& options) {
192192
scroll_->ScrollPointToCenter(point, options);
193193
}
194194

shell/browser/api/electron_api_scroll_view.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ScrollView : public BaseView {
4242
#endif // BUILDFLAG(IS_MAC)
4343

4444
#if defined(TOOLKIT_VIEWS) || BUILDFLAG(IS_MAC)
45-
void OnDidScroll(NativeView* observed_view) override;
45+
void OnDidScroll(NativeView* observed_view) override;
4646
#endif // defined(TOOLKIT_VIEWS) || BUILDFLAG(IS_MAC)
4747

4848
void SetContentView(v8::Local<v8::Value> value);
@@ -63,9 +63,8 @@ void OnDidScroll(NativeView* observed_view) override;
6363
void SetScrollPosition(gfx::Point point);
6464
gfx::Point GetScrollPosition() const;
6565
gfx::Point GetMaximumScrollPosition() const;
66-
void ScrollToPoint(gfx::Point point, const gin_helper::Dictionary& options);
67-
void ScrollPointToCenter(gfx::Point point,
68-
const gin_helper::Dictionary& options);
66+
void ScrollToPoint(gfx::Point point, const AnimationOptions& options);
67+
void ScrollPointToCenter(gfx::Point point, const AnimationOptions& options);
6968
void SetOverlayScrollbar(bool overlay);
7069
bool IsOverlayScrollbar() const;
7170
void SetScrollWheelFactor(double factor);
@@ -82,8 +81,8 @@ void OnDidScroll(NativeView* observed_view) override;
8281
bool GetDrawOverflowIndicator() const;
8382
#endif
8483
#if defined(TOOLKIT_VIEWS) || BUILDFLAG(IS_MAC)
85-
void SetScrollEventsEnabled(bool enable);
86-
bool IsScrollEventsEnabled();
84+
void SetScrollEventsEnabled(bool enable);
85+
bool IsScrollEventsEnabled();
8786
#endif // defined(TOOLKIT_VIEWS) || BUILDFLAG(IS_MAC)
8887

8988
private:

shell/browser/native_browser_view.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "content/public/browser/web_contents.h"
1111
#include "content/public/browser/web_contents_observer.h"
12+
#include "shell/browser/ui/view_utils.h"
1213
#include "shell/common/api/api.mojom.h"
1314
#include "third_party/skia/include/core/SkColor.h"
1415

@@ -17,10 +18,6 @@ class Image;
1718
class Rect;
1819
} // namespace gfx
1920

20-
namespace gin_helper {
21-
class Dictionary;
22-
}
23-
2421
namespace electron {
2522

2623
enum AutoResizeFlags {
@@ -57,17 +54,17 @@ class NativeBrowserView : public content::WebContentsObserver {
5754
virtual void SetAutoResizeFlags(uint8_t flags) = 0;
5855
virtual void SetBounds(const gfx::Rect& bounds) = 0;
5956
virtual void SetBounds(const gfx::Rect& bounds,
60-
const gin_helper::Dictionary& options) = 0;
57+
const BoundsAnimationOptions& options) = 0;
6158
virtual gfx::Rect GetBounds() = 0;
6259
virtual void SetBackgroundColor(SkColor color) = 0;
6360
virtual void SetViewBounds(const gfx::Rect& bounds) = 0;
6461
virtual gfx::Rect GetViewBounds() = 0;
6562
virtual void ResetScaling() = 0;
66-
virtual void SetScale(const gin_helper::Dictionary& options) = 0;
63+
virtual void SetScale(const ScaleAnimationOptions& options) = 0;
6764
virtual float GetScaleX() = 0;
6865
virtual float GetScaleY() = 0;
6966
virtual void SetOpacity(const double opacity,
70-
const gin_helper::Dictionary& options) = 0;
67+
const AnimationOptions& options) = 0;
7168
virtual double GetOpacity() = 0;
7269
virtual void SetVisible(bool visible) = 0;
7370
virtual bool IsVisible() = 0;

shell/browser/native_browser_view_mac.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ class NativeBrowserViewMac : public NativeBrowserView {
2222
void SetAutoResizeFlags(uint8_t flags) override;
2323
void SetBounds(const gfx::Rect& bounds) override;
2424
void SetBounds(const gfx::Rect& bounds,
25-
const gin_helper::Dictionary& options) override;
25+
const BoundsAnimationOptions& options) override;
2626
gfx::Rect GetBounds() override;
2727
void SetBackgroundColor(SkColor color) override;
2828
void SetViewBounds(const gfx::Rect& bounds) override;
2929
gfx::Rect GetViewBounds() override;
3030
void ResetScaling() override;
31-
void SetScale(const gin_helper::Dictionary& options) override;
31+
void SetScale(const ScaleAnimationOptions& options) override;
3232
float GetScaleX() override;
3333
float GetScaleY() override;
3434
void SetOpacity(const double opacity,
35-
const gin_helper::Dictionary& options) override;
35+
const AnimationOptions& options) override;
3636
double GetOpacity() override;
3737
void SetVisible(bool visible) override;
3838
bool IsVisible() override;

shell/browser/native_browser_view_mac.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "shell/browser/ui/inspectable_web_contents.h"
1212
#include "shell/browser/ui/inspectable_web_contents_view.h"
1313
#include "shell/browser/ui/view_utils.h"
14-
#include "shell/common/gin_helper/dictionary.h"
1514
#include "skia/ext/skia_utils_mac.h"
1615
#include "ui/gfx/geometry/rect.h"
1716

@@ -273,7 +272,7 @@ - (void)drawDebugRect:(NSRect)aRect {
273272
}
274273

275274
void NativeBrowserViewMac::SetBounds(const gfx::Rect& bounds,
276-
const gin_helper::Dictionary& options) {
275+
const BoundsAnimationOptions& options) {
277276
auto* iwc_view = GetInspectableWebContentsView();
278277
if (!iwc_view)
279278
return;
@@ -333,7 +332,7 @@ - (void)drawDebugRect:(NSRect)aRect {
333332
ResetScalingForView(view);
334333
}
335334

336-
void NativeBrowserViewMac::SetScale(const gin_helper::Dictionary& options) {
335+
void NativeBrowserViewMac::SetScale(const ScaleAnimationOptions& options) {
337336
auto* iwc_view = GetInspectableWebContentsView();
338337
if (!iwc_view)
339338
return;
@@ -358,7 +357,7 @@ - (void)drawDebugRect:(NSRect)aRect {
358357
}
359358

360359
void NativeBrowserViewMac::SetOpacity(const double opacity,
361-
const gin_helper::Dictionary& options) {
360+
const AnimationOptions& options) {
362361
auto* iwc_view = GetInspectableWebContentsView();
363362
if (!iwc_view)
364363
return;

0 commit comments

Comments
 (0)