Commit a2a8a9f7 authored by benwells's avatar benwells Committed by Commit bot

Animate showing / hiding the location bar for bookmark apps.

Bookmark apps no longer toggle whether they support the location bar
via the browser features system, which didn't seem correct. Instead they
support the location bar feature always but change how the location
bar's height to bring it into and out of view.

This change also introduces a BookmarkAppBrowserController class to
encapsulate all the logic for bookmark apps to modify the browser UI.

BUG=463405

Review URL: https://codereview.chromium.org/1036173002

Cr-Commit-Position: refs/heads/master@{#324020}
parent f49fd3bd
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_util.h" #include "extensions/browser/extension_util.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -27,13 +25,6 @@ bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) { ...@@ -27,13 +25,6 @@ bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) {
profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon);
} }
bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) {
return (app_url.scheme() == page_url.scheme() ||
page_url.scheme() == url::kHttpsScheme) &&
app_url.host() == page_url.host() &&
app_url.port() == page_url.port();
}
} // namespace } // namespace
namespace ui_util { namespace ui_util {
...@@ -69,26 +60,5 @@ bool ShouldNotBeVisible(const Extension* extension, ...@@ -69,26 +60,5 @@ bool ShouldNotBeVisible(const Extension* extension,
util::IsEphemeralApp(extension->id(), context); util::IsEphemeralApp(extension->id(), context);
} }
bool ShouldShowLocationBar(const Extension* extension,
const content::WebContents* web_contents) {
// Default to not showing the location bar if either |extension| or
// |web_contents| are null. |extension| is null for the dev tools.
if (!extension || !web_contents)
return false;
if (!extension->from_bookmark())
return false;
// Don't show a location bar until a navigation has occurred.
if (web_contents->GetLastCommittedURL().is_empty())
return false;
GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension);
return !(IsSameOriginOrMoreSecure(launch_url,
web_contents->GetVisibleURL()) &&
IsSameOriginOrMoreSecure(launch_url,
web_contents->GetLastCommittedURL()));
}
} // namespace ui_util } // namespace ui_util
} // namespace extensions } // namespace extensions
...@@ -47,11 +47,6 @@ bool ShouldDisplayInExtensionSettings(const Extension* extension, ...@@ -47,11 +47,6 @@ bool ShouldDisplayInExtensionSettings(const Extension* extension,
bool ShouldNotBeVisible(const Extension* extension, bool ShouldNotBeVisible(const Extension* extension,
content::BrowserContext* context); content::BrowserContext* context);
// Returns true if the location bar should be shown for |web_contents| when
// viewed in the context of the app represented by |extension|.
bool ShouldShowLocationBar(const Extension* extension,
const content::WebContents* web_contents);
} // namespace ui_util } // namespace ui_util
} // namespace extensions } // namespace extensions
......
...@@ -108,6 +108,7 @@ ...@@ -108,6 +108,7 @@
#include "chrome/browser/ui/chrome_select_file_policy.h" #include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h"
#include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h"
#include "chrome/browser/ui/fast_unload_controller.h" #include "chrome/browser/ui/fast_unload_controller.h"
#include "chrome/browser/ui/find_bar/find_bar.h" #include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h"
...@@ -140,7 +141,6 @@ ...@@ -140,7 +141,6 @@
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h" #include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/upgrade_detector.h" #include "chrome/browser/upgrade_detector.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/common/custom_handlers/protocol_handler.h"
...@@ -252,11 +252,6 @@ bool IsFastTabUnloadEnabled() { ...@@ -252,11 +252,6 @@ bool IsFastTabUnloadEnabled() {
switches::kEnableFastUnload); switches::kEnableFastUnload);
} }
bool IsWebAppFrameEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableWebAppFrame);
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -417,12 +412,20 @@ Browser::Browser(const CreateParams& params) ...@@ -417,12 +412,20 @@ Browser::Browser(const CreateParams& params)
if (chrome::IsInstantExtendedAPIEnabled() && is_type_tabbed()) if (chrome::IsInstantExtendedAPIEnabled() && is_type_tabbed())
instant_controller_.reset(new BrowserInstantController(this)); instant_controller_.reset(new BrowserInstantController(this));
if (extensions::BookmarkAppBrowserController::IsForBookmarkApp(this)) {
bookmark_app_controller_.reset(
new extensions::BookmarkAppBrowserController(this));
}
UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
ProfileMetrics::LogProfileLaunch(profile_); ProfileMetrics::LogProfileLaunch(profile_);
window_ = params.window ? params.window : CreateBrowserWindow(this); window_ = params.window ? params.window : CreateBrowserWindow(this);
if (bookmark_app_controller_)
bookmark_app_controller_->UpdateLocationBarVisibility(false);
// Create the extension window controller before sending notifications. // Create the extension window controller before sending notifications.
extension_window_controller_.reset( extension_window_controller_.reset(
new BrowserExtensionWindowController(this)); new BrowserExtensionWindowController(this));
...@@ -1411,6 +1414,9 @@ void Browser::NavigationStateChanged(WebContents* source, ...@@ -1411,6 +1414,9 @@ void Browser::NavigationStateChanged(WebContents* source,
if (changed_flags & (content::INVALIDATE_TYPE_URL | if (changed_flags & (content::INVALIDATE_TYPE_URL |
content::INVALIDATE_TYPE_LOAD)) content::INVALIDATE_TYPE_LOAD))
command_controller_->TabStateChanged(); command_controller_->TabStateChanged();
if (bookmark_app_controller_)
bookmark_app_controller_->UpdateLocationBarVisibility(true);
} }
void Browser::VisibleSSLStateChanged(const WebContents* source) { void Browser::VisibleSSLStateChanged(const WebContents* source) {
...@@ -2405,7 +2411,7 @@ void Browser::TabDetachedAtImpl(content::WebContents* contents, ...@@ -2405,7 +2411,7 @@ void Browser::TabDetachedAtImpl(content::WebContents* contents,
} }
} }
bool Browser::ShouldShowLocationBar() const { bool Browser::SupportsLocationBar() const {
// Tabbed browser always show a location bar. // Tabbed browser always show a location bar.
if (is_type_tabbed()) if (is_type_tabbed())
return true; return true;
...@@ -2415,34 +2421,22 @@ bool Browser::ShouldShowLocationBar() const { ...@@ -2415,34 +2421,22 @@ bool Browser::ShouldShowLocationBar() const {
if (!is_app()) if (!is_app())
return !is_trusted_source(); return !is_trusted_source();
if (ShouldUseWebAppFrame()) if (bookmark_app_controller_)
return false; return bookmark_app_controller_->SupportsLocationBar();
// Bookmark apps should show the location bar. return false;
const std::string extension_id =
web_app::GetExtensionIdFromApplicationName(app_name());
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile_)->GetExtensionById(
extension_id, extensions::ExtensionRegistry::EVERYTHING);
return extensions::ui_util::ShouldShowLocationBar(
extension, tab_strip_model_->GetActiveWebContents());
} }
bool Browser::ShouldUseWebAppFrame() const { bool Browser::ShouldUseWebAppFrame() const {
// Only use the web app frame for apps in ash, and only if the web app frame // Only use the web app frame for apps in ash, and only if the web app frame
// is enabled. // is enabled.
if (!is_app() || host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH || if (!is_app())
!IsWebAppFrameEnabled()) {
return false; return false;
}
// Use the web app frame for hosted apps. if (bookmark_app_controller_)
const std::string extension_id = return bookmark_app_controller_->should_use_web_app_frame();
web_app::GetExtensionIdFromApplicationName(app_name());
const extensions::Extension* extension = return false;
extensions::ExtensionRegistry::Get(profile_)->GetExtensionById(
extension_id, extensions::ExtensionRegistry::EVERYTHING);
return extension && extension->from_bookmark();
} }
bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
...@@ -2464,7 +2458,7 @@ bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, ...@@ -2464,7 +2458,7 @@ bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
if (is_type_tabbed()) if (is_type_tabbed())
features |= FEATURE_TOOLBAR; features |= FEATURE_TOOLBAR;
if (ShouldShowLocationBar()) if (SupportsLocationBar())
features |= FEATURE_LOCATIONBAR; features |= FEATURE_LOCATIONBAR;
if (ShouldUseWebAppFrame()) if (ShouldUseWebAppFrame())
......
...@@ -81,6 +81,7 @@ class SessionStorageNamespace; ...@@ -81,6 +81,7 @@ class SessionStorageNamespace;
} }
namespace extensions { namespace extensions {
class BookmarkAppBrowserController;
class Extension; class Extension;
class ExtensionRegistry; class ExtensionRegistry;
class WindowController; class WindowController;
...@@ -282,6 +283,9 @@ class Browser : public TabStripModelObserver, ...@@ -282,6 +283,9 @@ class Browser : public TabStripModelObserver,
BrowserInstantController* instant_controller() { BrowserInstantController* instant_controller() {
return instant_controller_.get(); return instant_controller_.get();
} }
extensions::BookmarkAppBrowserController* bookmark_app_controller() {
return bookmark_app_controller_.get();
}
// Get the FindBarController for this browser, creating it if it does not // Get the FindBarController for this browser, creating it if it does not
// yet exist. // yet exist.
...@@ -798,6 +802,10 @@ class Browser : public TabStripModelObserver, ...@@ -798,6 +802,10 @@ class Browser : public TabStripModelObserver,
// Shared code between Reload() and ReloadIgnoringCache(). // Shared code between Reload() and ReloadIgnoringCache().
void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
// Returns true if the Browser window supports a location bar. Having support
// for the location bar does not mean it will be visible.
bool SupportsLocationBar() const;
// Returns true if the Browser window should show the location bar. // Returns true if the Browser window should show the location bar.
bool ShouldShowLocationBar() const; bool ShouldShowLocationBar() const;
...@@ -955,6 +963,9 @@ class Browser : public TabStripModelObserver, ...@@ -955,6 +963,9 @@ class Browser : public TabStripModelObserver,
scoped_ptr<BrowserInstantController> instant_controller_; scoped_ptr<BrowserInstantController> instant_controller_;
// Helper which handles bookmark app specific browser configuration.
scoped_ptr<extensions::BookmarkAppBrowserController> bookmark_app_controller_;
BookmarkBar::State bookmark_bar_state_; BookmarkBar::State bookmark_bar_state_;
scoped_ptr<ExclusiveAccessManager> exclusive_access_manager_; scoped_ptr<ExclusiveAccessManager> exclusive_access_manager_;
......
...@@ -178,6 +178,9 @@ class BrowserWindow : public ui::BaseWindow { ...@@ -178,6 +178,9 @@ class BrowserWindow : public ui::BaseWindow {
// Focuses the toolbar (for accessibility). // Focuses the toolbar (for accessibility).
virtual void FocusToolbar() = 0; virtual void FocusToolbar() = 0;
// Called from toolbar subviews during their show/hide animations.
virtual void ToolbarSizeChanged(bool is_animating) = 0;
// Focuses the app menu like it was a menu bar. // Focuses the app menu like it was a menu bar.
// //
// Not used on the Mac, which has a "normal" menu bar. // Not used on the Mac, which has a "normal" menu bar.
......
...@@ -95,6 +95,7 @@ class BrowserWindowCocoa ...@@ -95,6 +95,7 @@ class BrowserWindowCocoa
void UpdateToolbar(content::WebContents* contents) override; void UpdateToolbar(content::WebContents* contents) override;
void ResetToolbarTabState(content::WebContents* contents) override; void ResetToolbarTabState(content::WebContents* contents) override;
void FocusToolbar() override; void FocusToolbar() override;
void ToolbarSizeChanged(bool is_animating) override;
void FocusAppMenu() override; void FocusAppMenu() override;
void FocusBookmarksToolbar() override; void FocusBookmarksToolbar() override;
void FocusInfobars() override; void FocusInfobars() override;
......
...@@ -476,6 +476,10 @@ void BrowserWindowCocoa::FocusToolbar() { ...@@ -476,6 +476,10 @@ void BrowserWindowCocoa::FocusToolbar() {
// Not needed on the Mac. // Not needed on the Mac.
} }
void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
// Not needed on the Mac.
}
void BrowserWindowCocoa::FocusAppMenu() { void BrowserWindowCocoa::FocusAppMenu() {
// Chrome uses the standard Mac OS X menu bar, so this isn't needed. // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
} }
......
...@@ -67,6 +67,7 @@ class LocationBarViewMac : public LocationBar, ...@@ -67,6 +67,7 @@ class LocationBarViewMac : public LocationBar,
void UpdateManagePasswordsIconAndBubble() override; void UpdateManagePasswordsIconAndBubble() override;
void UpdatePageActions() override; void UpdatePageActions() override;
void UpdateBookmarkStarVisibility() override; void UpdateBookmarkStarVisibility() override;
void UpdateLocationBarVisibility(bool visible, bool animate) override;
bool ShowPageActionPopup(const extensions::Extension* extension, bool ShowPageActionPopup(const extensions::Extension* extension,
bool grant_active_tab) override; bool grant_active_tab) override;
void UpdateOpenPDFInReaderPrompt() override; void UpdateOpenPDFInReaderPrompt() override;
......
...@@ -202,6 +202,11 @@ void LocationBarViewMac::UpdateBookmarkStarVisibility() { ...@@ -202,6 +202,11 @@ void LocationBarViewMac::UpdateBookmarkStarVisibility() {
star_decoration_->SetVisible(IsStarEnabled()); star_decoration_->SetVisible(IsStarEnabled());
} }
void LocationBarViewMac::UpdateLocationBarVisibility(bool visible,
bool animate) {
// Not implemented on Mac.
}
bool LocationBarViewMac::ShowPageActionPopup( bool LocationBarViewMac::ShowPageActionPopup(
const extensions::Extension* extension, bool grant_active_tab) { const extensions::Extension* extension, bool grant_active_tab) {
for (ScopedVector<PageActionDecoration>::iterator iter = for (ScopedVector<PageActionDecoration>::iterator iter =
......
// Copyright 2015 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.
#include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h"
#include "base/command_line.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "url/gurl.h"
namespace extensions {
namespace {
bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) {
return (app_url.scheme() == page_url.scheme() ||
page_url.scheme() == url::kHttpsScheme) &&
app_url.host() == page_url.host() &&
app_url.port() == page_url.port();
}
bool IsWebAppFrameEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableWebAppFrame);
}
} // namespace
// static
bool BookmarkAppBrowserController::IsForBookmarkApp(Browser* browser) {
const std::string extension_id =
web_app::GetExtensionIdFromApplicationName(browser->app_name());
const Extension* extension =
ExtensionRegistry::Get(browser->profile())->GetExtensionById(
extension_id, ExtensionRegistry::EVERYTHING);
return extension && extension->from_bookmark();
}
BookmarkAppBrowserController::BookmarkAppBrowserController(Browser* browser)
: browser_(browser),
extension_id_(
web_app::GetExtensionIdFromApplicationName(browser->app_name())),
should_use_web_app_frame_(browser->host_desktop_type() ==
chrome::HOST_DESKTOP_TYPE_ASH &&
IsWebAppFrameEnabled()) {
}
BookmarkAppBrowserController::~BookmarkAppBrowserController() {
}
bool BookmarkAppBrowserController::SupportsLocationBar() {
return !should_use_web_app_frame();
}
bool BookmarkAppBrowserController::ShouldShowLocationBar() {
const Extension* extension =
ExtensionRegistry::Get(browser_->profile())->GetExtensionById(
extension_id_, ExtensionRegistry::EVERYTHING);
const content::WebContents* web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
// Default to not showing the location bar if either |extension| or
// |web_contents| are null. |extension| is null for the dev tools.
if (!extension || !web_contents)
return false;
if (!extension->from_bookmark())
return false;
// Don't show a location bar until a navigation has occurred.
if (web_contents->GetLastCommittedURL().is_empty())
return false;
GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension);
return !(IsSameOriginOrMoreSecure(launch_url,
web_contents->GetVisibleURL()) &&
IsSameOriginOrMoreSecure(launch_url,
web_contents->GetLastCommittedURL()));
}
void BookmarkAppBrowserController::UpdateLocationBarVisibility(bool animate) {
if (!SupportsLocationBar())
return;
browser_->window()->GetLocationBar()->UpdateLocationBarVisibility(
ShouldShowLocationBar(), animate);
}
} // namespace extensions
// Copyright 2015 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.
#ifndef CHROME_BROWSER_UI_EXTENSIONS_BOOKMARK_APP_BROWSER_CONTROLLER_H_
#define CHROME_BROWSER_UI_EXTENSIONS_BOOKMARK_APP_BROWSER_CONTROLLER_H_
#include <string>
#include "base/macros.h"
class Browser;
class Profile;
namespace extensions {
// Class to encapsulate logic to control the browser UI for bookmark apps.
class BookmarkAppBrowserController {
public:
// Indicates whether |browser| is a bookmark app browser.
static bool IsForBookmarkApp(Browser* browser);
explicit BookmarkAppBrowserController(Browser* browser);
~BookmarkAppBrowserController();
// Whether the browser being controlled can ever show the location bar.
bool SupportsLocationBar();
// Whether the browser being controlled should be currently showing the
// location bar.
bool ShouldShowLocationBar();
// Updates the location bar visibility based on whether it should be
// currently visible or not. If |animate| is set, the change will be
// animated.
void UpdateLocationBarVisibility(bool animate);
// Whether the controlled browser should use the web app style frame.
bool should_use_web_app_frame() { return should_use_web_app_frame_; }
private:
Browser* browser_;
const std::string extension_id_;
const bool should_use_web_app_frame_;
DISALLOW_COPY_AND_ASSIGN(BookmarkAppBrowserController);
};
} // namespace extensions
#endif // CHROME_BROWSER_UI_EXTENSIONS_BOOKMARK_APP_BROWSER_CONTROLLER_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/browser_iterator.h" #include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/extensions/app_launch_params.h" #include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -39,7 +40,7 @@ void NavigateAndCheckForLocationBar(Browser* browser, ...@@ -39,7 +40,7 @@ void NavigateAndCheckForLocationBar(Browser* browser,
GURL url(url_string); GURL url(url_string);
ui_test_utils::NavigateToURL(browser, url); ui_test_utils::NavigateToURL(browser, url);
EXPECT_EQ(expected_visibility, EXPECT_EQ(expected_visibility,
browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); browser->bookmark_app_controller()->ShouldShowLocationBar());
} }
} // namespace } // namespace
......
...@@ -61,6 +61,10 @@ class LocationBar { ...@@ -61,6 +61,10 @@ class LocationBar {
// Updates the visibility of the bookmark star. // Updates the visibility of the bookmark star.
virtual void UpdateBookmarkStarVisibility() = 0; virtual void UpdateBookmarkStarVisibility() = 0;
// Updates the visibility of the location bar. Animates the transition if
// |animate| is true.
virtual void UpdateLocationBarVisibility(bool visible, bool animate) = 0;
// Shows the popup for the given |extension| and, if |grant_active_tab| is // Shows the popup for the given |extension| and, if |grant_active_tab| is
// true, grants the extension active tab permissions. // true, grants the extension active tab permissions.
// Returns true if a popup was shown. // Returns true if a popup was shown.
......
...@@ -1035,44 +1035,6 @@ void BrowserView::FullscreenStateChanged() { ...@@ -1035,44 +1035,6 @@ void BrowserView::FullscreenStateChanged() {
EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE); EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
} }
void BrowserView::ToolbarSizeChanged(bool is_animating) {
// The call to SetMaxTopArrowHeight() below can result in reentrancy;
// |call_state| tracks whether we're reentrant. We can't just early-return in
// this case because we need to layout again so the infobar container's bounds
// are set correctly.
static CallState call_state = NORMAL;
// A reentrant call can (and should) use the fast resize path unless both it
// and the normal call are both non-animating.
bool use_fast_resize =
is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE);
if (use_fast_resize)
contents_web_view_->SetFastResize(true);
UpdateUIForContents(GetActiveWebContents());
if (use_fast_resize)
contents_web_view_->SetFastResize(false);
// Inform the InfoBarContainer that the distance to the location icon may have
// changed. We have to do this after the block above so that the toolbars are
// laid out correctly for calculating the maximum arrow height below.
{
base::AutoReset<CallState> resetter(&call_state,
is_animating ? REENTRANT_FORCE_FAST_RESIZE : REENTRANT);
SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_);
}
// When transitioning from animating to not animating we need to make sure the
// contents_container_ gets layed out. If we don't do this and the bounds
// haven't changed contents_container_ won't get a Layout out and we'll end up
// with a gray rect because the clip wasn't updated. Note that a reentrant
// call never needs to do this, because after it returns, the normal call
// wrapping it will do it.
if ((call_state == NORMAL) && !is_animating) {
contents_web_view_->InvalidateLayout();
contents_container_->Layout();
}
}
LocationBar* BrowserView::GetLocationBar() const { LocationBar* BrowserView::GetLocationBar() const {
return GetLocationBarView(); return GetLocationBarView();
} }
...@@ -1139,6 +1101,44 @@ void BrowserView::FocusToolbar() { ...@@ -1139,6 +1101,44 @@ void BrowserView::FocusToolbar() {
toolbar_->SetPaneFocus(nullptr); toolbar_->SetPaneFocus(nullptr);
} }
void BrowserView::ToolbarSizeChanged(bool is_animating) {
// The call to SetMaxTopArrowHeight() below can result in reentrancy;
// |call_state| tracks whether we're reentrant. We can't just early-return in
// this case because we need to layout again so the infobar container's bounds
// are set correctly.
static CallState call_state = NORMAL;
// A reentrant call can (and should) use the fast resize path unless both it
// and the normal call are both non-animating.
bool use_fast_resize =
is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE);
if (use_fast_resize)
contents_web_view_->SetFastResize(true);
UpdateUIForContents(GetActiveWebContents());
if (use_fast_resize)
contents_web_view_->SetFastResize(false);
// Inform the InfoBarContainer that the distance to the location icon may have
// changed. We have to do this after the block above so that the toolbars are
// laid out correctly for calculating the maximum arrow height below.
{
base::AutoReset<CallState> resetter(&call_state,
is_animating ? REENTRANT_FORCE_FAST_RESIZE : REENTRANT);
SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight(), infobar_container_);
}
// When transitioning from animating to not animating we need to make sure the
// contents_container_ gets layed out. If we don't do this and the bounds
// haven't changed contents_container_ won't get a Layout out and we'll end up
// with a gray rect because the clip wasn't updated. Note that a reentrant
// call never needs to do this, because after it returns, the normal call
// wrapping it will do it.
if ((call_state == NORMAL) && !is_animating) {
contents_web_view_->InvalidateLayout();
contents_container_->Layout();
}
}
void BrowserView::FocusBookmarksToolbar() { void BrowserView::FocusBookmarksToolbar() {
DCHECK(!immersive_mode_controller_->IsEnabled()); DCHECK(!immersive_mode_controller_->IsEnabled());
if (bookmark_bar_view_.get() && if (bookmark_bar_view_.get() &&
......
...@@ -232,10 +232,6 @@ class BrowserView : public BrowserWindow, ...@@ -232,10 +232,6 @@ class BrowserView : public BrowserWindow,
// Only exiting fullscreen in this way is currently supported. // Only exiting fullscreen in this way is currently supported.
void FullscreenStateChanged(); void FullscreenStateChanged();
// Called from BookmarkBarView/DownloadShelfView during their show/hide
// animations.
void ToolbarSizeChanged(bool is_animating);
// Overridden from BrowserWindow: // Overridden from BrowserWindow:
void Show() override; void Show() override;
void ShowInactive() override; void ShowInactive() override;
...@@ -293,6 +289,7 @@ class BrowserView : public BrowserWindow, ...@@ -293,6 +289,7 @@ class BrowserView : public BrowserWindow,
void UpdateToolbar(content::WebContents* contents) override; void UpdateToolbar(content::WebContents* contents) override;
void ResetToolbarTabState(content::WebContents* contents) override; void ResetToolbarTabState(content::WebContents* contents) override;
void FocusToolbar() override; void FocusToolbar() override;
void ToolbarSizeChanged(bool is_animating) override;
void FocusAppMenu() override; void FocusAppMenu() override;
void FocusBookmarksToolbar() override; void FocusBookmarksToolbar() override;
void FocusInfobars() override; void FocusInfobars() override;
......
...@@ -143,6 +143,7 @@ LocationBarView::LocationBarView(Browser* browser, ...@@ -143,6 +143,7 @@ LocationBarView::LocationBarView(Browser* browser,
manage_passwords_icon_view_(NULL), manage_passwords_icon_view_(NULL),
translate_icon_view_(NULL), translate_icon_view_(NULL),
star_view_(NULL), star_view_(NULL),
size_animation_(this),
is_popup_mode_(is_popup_mode), is_popup_mode_(is_popup_mode),
show_focus_rect_(false), show_focus_rect_(false),
template_url_service_(NULL), template_url_service_(NULL),
...@@ -305,6 +306,8 @@ void LocationBarView::Init() { ...@@ -305,6 +306,8 @@ void LocationBarView::Init() {
// Initialize the location entry. We do this to avoid a black flash which is // Initialize the location entry. We do this to avoid a black flash which is
// visible when the location entry has just been initialized. // visible when the location entry has just been initialized.
Update(NULL); Update(NULL);
size_animation_.Reset(1);
} }
bool LocationBarView::IsInitialized() const { bool LocationBarView::IsInitialized() const {
...@@ -528,6 +531,8 @@ gfx::Size LocationBarView::GetPreferredSize() const { ...@@ -528,6 +531,8 @@ gfx::Size LocationBarView::GetPreferredSize() const {
if (!IsInitialized()) if (!IsInitialized())
return min_size; return min_size;
min_size.set_height(min_size.height() * size_animation_.GetCurrentValue());
// Compute width of omnibox-leading content. // Compute width of omnibox-leading content.
const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
int leading_width = horizontal_edge_thickness; int leading_width = horizontal_edge_thickness;
...@@ -1066,6 +1071,18 @@ void LocationBarView::UpdateBookmarkStarVisibility() { ...@@ -1066,6 +1071,18 @@ void LocationBarView::UpdateBookmarkStarVisibility() {
} }
} }
void LocationBarView::UpdateLocationBarVisibility(bool visible, bool animate) {
if (!animate) {
size_animation_.Reset(visible ? 1 : 0);
return;
}
if (visible)
size_animation_.Show();
else
size_animation_.Hide();
}
bool LocationBarView::ShowPageActionPopup( bool LocationBarView::ShowPageActionPopup(
const extensions::Extension* extension, const extensions::Extension* extension,
bool grant_tab_permissions) { bool grant_tab_permissions) {
...@@ -1286,6 +1303,16 @@ bool LocationBarView::CanStartDragForView(View* sender, ...@@ -1286,6 +1303,16 @@ bool LocationBarView::CanStartDragForView(View* sender,
return true; return true;
} }
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private gfx::AnimationDelegate implementation:
void LocationBarView::AnimationProgressed(const gfx::Animation* animation) {
browser_->window()->ToolbarSizeChanged(true);
}
void LocationBarView::AnimationEnded(const gfx::Animation* animation) {
browser_->window()->ToolbarSizeChanged(false);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private OmniboxEditController implementation: // LocationBarView, private OmniboxEditController implementation:
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "components/search_engines/template_url_service_observer.h" #include "components/search_engines/template_url_service_observer.h"
#include "components/ui/zoom/zoom_event_manager_observer.h" #include "components/ui/zoom/zoom_event_manager_observer.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -74,6 +75,7 @@ class LocationBarView : public LocationBar, ...@@ -74,6 +75,7 @@ class LocationBarView : public LocationBar,
public views::View, public views::View,
public views::ButtonListener, public views::ButtonListener,
public views::DragController, public views::DragController,
public gfx::AnimationDelegate,
public OmniboxEditController, public OmniboxEditController,
public DropdownBarHostDelegate, public DropdownBarHostDelegate,
public TemplateURLServiceObserver, public TemplateURLServiceObserver,
...@@ -347,6 +349,7 @@ class LocationBarView : public LocationBar, ...@@ -347,6 +349,7 @@ class LocationBarView : public LocationBar,
void UpdateManagePasswordsIconAndBubble() override; void UpdateManagePasswordsIconAndBubble() override;
void UpdatePageActions() override; void UpdatePageActions() override;
void UpdateBookmarkStarVisibility() override; void UpdateBookmarkStarVisibility() override;
void UpdateLocationBarVisibility(bool visible, bool animation) override;
bool ShowPageActionPopup(const extensions::Extension* extension, bool ShowPageActionPopup(const extensions::Extension* extension,
bool grant_active_tab) override; bool grant_active_tab) override;
void UpdateOpenPDFInReaderPrompt() override; void UpdateOpenPDFInReaderPrompt() override;
...@@ -382,6 +385,10 @@ class LocationBarView : public LocationBar, ...@@ -382,6 +385,10 @@ class LocationBarView : public LocationBar,
const gfx::Point& press_pt, const gfx::Point& press_pt,
const gfx::Point& p) override; const gfx::Point& p) override;
// gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
// OmniboxEditController: // OmniboxEditController:
void OnChanged() override; void OnChanged() override;
void OnSetFocus() override; void OnSetFocus() override;
...@@ -467,6 +474,9 @@ class LocationBarView : public LocationBar, ...@@ -467,6 +474,9 @@ class LocationBarView : public LocationBar,
// The star. // The star.
StarView* star_view_; StarView* star_view_;
// Animation to control showing / hiding the location bar.
gfx::SlideAnimation size_animation_;
// Whether we're in popup mode. This value also controls whether the location // Whether we're in popup mode. This value also controls whether the location
// bar is read-only. // bar is read-only.
const bool is_popup_mode_; const bool is_popup_mode_;
......
...@@ -738,6 +738,13 @@ gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { ...@@ -738,6 +738,13 @@ gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const {
GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
size.SetToMax( size.SetToMax(
gfx::Size(0, normal_background->height() - content_shadow_height())); gfx::Size(0, normal_background->height() - content_shadow_height()));
} else if (size.height() == 0) {
// Location mode with a 0 height location bar. If on ash, expand by one
// pixel to show a border in the title bar, otherwise leave the size as zero
// height.
const int kAshBorderSpacing = 1;
if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH)
size.Enlarge(0, kAshBorderSpacing);
} else { } else {
const int kPopupBottomSpacingGlass = 1; const int kPopupBottomSpacingGlass = 1;
const int kPopupBottomSpacingNonGlass = 2; const int kPopupBottomSpacingNonGlass = 2;
......
...@@ -2543,6 +2543,8 @@ ...@@ -2543,6 +2543,8 @@
'browser/ui/extensions/app_launch_params.h', 'browser/ui/extensions/app_launch_params.h',
'browser/ui/extensions/application_launch.cc', 'browser/ui/extensions/application_launch.cc',
'browser/ui/extensions/application_launch.h', 'browser/ui/extensions/application_launch.h',
'browser/ui/extensions/bookmark_app_browser_controller.cc',
'browser/ui/extensions/bookmark_app_browser_controller.h',
'browser/ui/extensions/extension_action_platform_delegate.h', 'browser/ui/extensions/extension_action_platform_delegate.h',
'browser/ui/extensions/extension_action_view_controller.cc', 'browser/ui/extensions/extension_action_view_controller.cc',
'browser/ui/extensions/extension_action_view_controller.h', 'browser/ui/extensions/extension_action_view_controller.h',
......
...@@ -85,6 +85,7 @@ class TestBrowserWindow : public BrowserWindow { ...@@ -85,6 +85,7 @@ class TestBrowserWindow : public BrowserWindow {
void UpdateToolbar(content::WebContents* contents) override {} void UpdateToolbar(content::WebContents* contents) override {}
void ResetToolbarTabState(content::WebContents* contents) override {} void ResetToolbarTabState(content::WebContents* contents) override {}
void FocusToolbar() override {} void FocusToolbar() override {}
void ToolbarSizeChanged(bool is_animating) override {}
void FocusAppMenu() override {} void FocusAppMenu() override {}
void FocusBookmarksToolbar() override {} void FocusBookmarksToolbar() override {}
void FocusInfobars() override {} void FocusInfobars() override {}
...@@ -172,6 +173,7 @@ class TestBrowserWindow : public BrowserWindow { ...@@ -172,6 +173,7 @@ class TestBrowserWindow : public BrowserWindow {
void UpdateManagePasswordsIconAndBubble() override {} void UpdateManagePasswordsIconAndBubble() override {}
void UpdatePageActions() override {} void UpdatePageActions() override {}
void UpdateBookmarkStarVisibility() override {} void UpdateBookmarkStarVisibility() override {}
void UpdateLocationBarVisibility(bool visible, bool animate) override {}
bool ShowPageActionPopup(const extensions::Extension* extension, bool ShowPageActionPopup(const extensions::Extension* extension,
bool grant_active_tab) override; bool grant_active_tab) override;
void UpdateOpenPDFInReaderPrompt() override {} void UpdateOpenPDFInReaderPrompt() override {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment