From eeb2e58ad88714c4489f6a7c09268aeffd05a6e6 Mon Sep 17 00:00:00 2001 From: Siyuan Liu Date: Sun, 20 Aug 2017 22:48:13 +0800 Subject: [PATCH 1/4] return null when theme color is not found --- atom/browser/api/atom_api_web_contents.cc | 6 +++++- docs/api/web-contents.md | 6 ++++++ spec/api-web-contents-spec.js | 17 +++++++++++++++++ vendor/native_mate | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 244c52654c53..06f1c4e8a9b5 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -757,7 +757,11 @@ void WebContents::MediaStoppedPlaying(const MediaPlayerInfo& video_type, } void WebContents::DidChangeThemeColor(SkColor theme_color) { - Emit("did-change-theme-color", atom::ToRGBHex(theme_color)); + if (theme_color != SK_ColorTRANSPARENT) { + Emit("did-change-theme-color", atom::ToRGBHex(theme_color)); + } else { + Emit("did-change-theme-color", nullptr_t()); + } } void WebContents::DocumentLoadedInFrame( diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 9c58e1a4edef..7088d25ad0cb 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -403,6 +403,12 @@ a meta tag: ``` +Returns: + +* `event` Event +* `color` string + * Theme color in format '#rrggbb'. `null` when theme color is not found. + #### Event: 'update-target-url' Returns: diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index ca35a231f4b9..b00c6b27c9be 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -654,4 +654,21 @@ describe('webContents module', function () { gen.next() }) }) + + describe('did-change-theme-color event', () => { + it('is triggered with correct theme color', (done) => { + var count = 0 + w.webContents.on('did-change-theme-color', (e, color) => { + if (count === 0) { + count++ + assert.equal(color, '#FFEEDD') + w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html')) + } else if (count === 1) { + assert.equal(color, null) + done() + } + }) + w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'theme-color.html')) + }) + }) }) diff --git a/vendor/native_mate b/vendor/native_mate index 7d9c1a80f025..f047bb61bbd9 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit 7d9c1a80f025f4c46f7da8ea73246fe0f1968579 +Subproject commit f047bb61bbd985079dd93e7ed322999550efed1d From 5cb58cd42f39f980f31441b0ede3c35fabd4b359 Mon Sep 17 00:00:00 2001 From: Siyuan Liu Date: Wed, 23 Aug 2017 09:30:58 +0800 Subject: [PATCH 2/4] use nullptr instead of nullptr_t() --- atom/browser/api/atom_api_web_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 06f1c4e8a9b5..d02e8085d929 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -760,7 +760,7 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) { if (theme_color != SK_ColorTRANSPARENT) { Emit("did-change-theme-color", atom::ToRGBHex(theme_color)); } else { - Emit("did-change-theme-color", nullptr_t()); + Emit("did-change-theme-color", nullptr); } } From 15d2cfe45861a2b098dcf9a4312edb72dadf68a2 Mon Sep 17 00:00:00 2001 From: Liu Siyuan Date: Wed, 23 Aug 2017 23:04:00 +0800 Subject: [PATCH 3/4] update docs --- docs/api/web-contents.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 7088d25ad0cb..6b571874e35b 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -406,8 +406,8 @@ a meta tag: Returns: * `event` Event -* `color` string - * Theme color in format '#rrggbb'. `null` when theme color is not found. +* `color` string or `null` + * Theme color in format '#rrggbb'. `null` when theme color is not set. #### Event: 'update-target-url' From e64d4e5bd724c8deac9316214130508a44538cbf Mon Sep 17 00:00:00 2001 From: Liu Siyuan Date: Wed, 23 Aug 2017 23:37:37 +0800 Subject: [PATCH 4/4] update web-content.md based on review --- docs/api/web-contents.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 6b571874e35b..78f7ee333f5b 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -406,8 +406,7 @@ a meta tag: Returns: * `event` Event -* `color` string or `null` - * Theme color in format '#rrggbb'. `null` when theme color is not set. +* `color` (String | null) - Theme color is in format of '#rrggbb'. It is `null` when no theme color is set. #### Event: 'update-target-url'