From 283048910f37e1dc05fc19a2736dd3b337320036 Mon Sep 17 00:00:00 2001 From: Radoslav Vitanov Date: Mon, 12 Sep 2016 22:51:05 +0300 Subject: [PATCH] Address bar should be active for about:newtab This issue was fixed via https://github.com/brave/browser-laptop/pull/3718 but was returned with feedback from the QA. Now it should properly handle switching to new tab via shortcut or mouse. Fixes #3712 Auditors: @bbondy Test Plan: While switching to a new tab eighter via shortcut or mouse click the url bar should be focused. --- docs/windowActions.md | 10 ++++++++++ js/actions/windowActions.js | 11 +++++++++++ js/components/frame.js | 2 +- js/components/tab.js | 9 ++++++++- js/constants/windowConstants.js | 1 + js/stores/windowStore.js | 3 +++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/windowActions.md b/docs/windowActions.md index 7c42760a9b7..830cc0362ee 100644 --- a/docs/windowActions.md +++ b/docs/windowActions.md @@ -408,6 +408,16 @@ are no autocomplete results. +### setUrlBarFocused(isFocused) + +Marks the URL bar as focused or not. + +**Parameters** + +**isFocused**: `boolean`, Whether or not the URL bar should be marked as focused + + + ### setActiveFrameShortcut(frameProps, activeShortcut, activeShortcutDetails) Dispatches a message to the store to indicate that the pending frame shortcut info should be updated. diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index e9046b4071c..9a5d0e5fde4 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -574,6 +574,17 @@ const windowActions = { }) }, + /** + * Marks the URL bar as focused or not. + * + * @param {boolean} isFocused - Whether or not the URL bar should be marked as focused + */ + setUrlBarFocused: function (isFocused) { + dispatch({ + actionType: WindowConstants.WINDOW_SET_URL_BAR_FOCUSED, + isFocused + }) + }, /** * Dispatches a message to the store to indicate that the pending frame shortcut info should be updated. * diff --git a/js/components/frame.js b/js/components/frame.js index 939bd671fe3..df0e4fe9b3a 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -356,7 +356,7 @@ class Frame extends ImmutableComponent { // to the UrlBar if (this.props.location === 'about:newtab') { windowActions.setUrlBarActive(true) - windowActions.setUrlBarSelected(false) + windowActions.setUrlBarFocused(true) } else { // If it is a regular webpage, just focus the webcontents this.webview.focus() diff --git a/js/components/tab.js b/js/components/tab.js index 923676a0535..c752bb85b69 100644 --- a/js/components/tab.js +++ b/js/components/tab.js @@ -86,8 +86,15 @@ class Tab extends ImmutableComponent { dnd.onDragOver(dragTypes.TAB, this.tabNode.getBoundingClientRect(), this.props.tab.get('frameKey'), this.draggingOverData, e) } - setActiveFrame () { + setActiveFrame (event) { + event.stopPropagation() windowActions.setActiveFrame(this.frame) + + if (this.frame.get('location') === 'about:newtab') { + windowActions.setUrlBarActive(true) + windowActions.setUrlBarFocused(true) + windowActions.setUrlBarSelected(false) + } } onCloseFrame (event) { diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index a24bfa04c7a..57457442e78 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -39,6 +39,7 @@ const windowConstants = { WINDOW_CLEAR_CLOSED_FRAMES: _, WINDOW_SET_ACTIVE_FRAME_SHORTCUT: _, WINDOW_SET_URL_BAR_SELECTED: _, + WINDOW_SET_URL_BAR_FOCUSED: _, WINDOW_SET_SEARCH_DETAIL: _, WINDOW_SET_FIND_DETAIL: _, WINDOW_SET_BOOKMARK_DETAIL: _, // If set, also indicates that add/edit is shown diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index a7317d965b3..43d6ae50c9d 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -555,6 +555,9 @@ const doAction = (action) => { case WindowConstants.WINDOW_SET_URL_BAR_AUTCOMPLETE_ENABLED: windowState = windowState.setIn(activeFrameStatePath().concat(['navbar', 'urlbar', 'suggestions', 'autocompleteEnabled']), action.enabled) break + case WindowConstants.WINDOW_SET_URL_BAR_FOCUSED: + windowState = windowState.setIn(activeFrameStatePath().concat(['navbar', 'urlbar', 'focused']), action.isFocused) + break case WindowConstants.WINDOW_SET_URL_BAR_SELECTED: const urlBarPath = activeFrameStatePath().concat(['navbar', 'urlbar']) windowState = windowState.mergeIn(urlBarPath, {