summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-02 04:18:08 +0000
committerjennb@chromium.org <jennb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-02 04:18:08 +0000
commit5843d6bd616b7011e15126ee8264c867b35decfd (patch)
tree05169977f6ed33cd28603005dd9fb349fc7f20cd
parentc08f2717d40daa9474552deab81d697ea4de08fa (diff)
downloadchromium_src-5843d6bd616b7011e15126ee8264c867b35decfd.zip
chromium_src-5843d6bd616b7011e15126ee8264c867b35decfd.tar.gz
chromium_src-5843d6bd616b7011e15126ee8264c867b35decfd.tar.bz2
Further isolation of browser window logic from Panel framework.
Created temporary OldPanel subclass of Panel that still provides the functionality through a browser. Hid PanelBrowserWindowCocoa from the window controller by creating a NativePanelCocoa interface. Changed Cocoa panel window controller to access functionality through Panel rather than from the Browser directly. When a panel is deactivated, Cocoa no longer finds last active browser to activate. Updated tests that were unnecessarily calling panel->deactivate(). BUG=127323 TEST=Updated Review URL: https://chromiumcodereview.appspot.com/10447136 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140174 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/panels/detached_panel_browsertest.cc23
-rw-r--r--chrome/browser/ui/panels/native_panel_cocoa.h26
-rw-r--r--chrome/browser/ui/panels/old_panel.cc60
-rw-r--r--chrome/browser/ui/panels/old_panel.h43
-rw-r--r--chrome/browser/ui/panels/panel.cc86
-rw-r--r--chrome/browser/ui/panels/panel.h68
-rw-r--r--chrome/browser/ui/panels/panel_browser_frame_view.cc2
-rw-r--r--chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc3
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa.h25
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa.mm13
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm10
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc44
-rw-r--r--chrome/browser/ui/panels/panel_manager.cc3
-rw-r--r--chrome/browser/ui/panels/panel_window_controller_cocoa.h20
-rw-r--r--chrome/browser/ui/panels/panel_window_controller_cocoa.mm92
-rw-r--r--chrome/chrome_browser.gypi3
16 files changed, 384 insertions, 137 deletions
diff --git a/chrome/browser/ui/panels/detached_panel_browsertest.cc b/chrome/browser/ui/panels/detached_panel_browsertest.cc
index fb0a6c2..e84d269 100644
--- a/chrome/browser/ui/panels/detached_panel_browsertest.cc
+++ b/chrome/browser/ui/panels/detached_panel_browsertest.cc
@@ -86,27 +86,28 @@ IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionOnInactive) {
}
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, DrawAttentionResetOnActivate) {
- // Create an inactive detached panel.
- Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
- panel->Deactivate();
- WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
+ // Create 2 panels so we end up with an inactive panel that can
+ // be made to draw attention.
+ Panel* panel1 = CreatePanel("test panel1");
+ Panel* panel2 = CreatePanel("test panel2");
scoped_ptr<NativePanelTesting> native_panel_testing(
- NativePanelTesting::Create(panel->native_panel()));
+ NativePanelTesting::Create(panel1->native_panel()));
// Test that the attention is drawn when the detached panel is not in focus.
- panel->FlashFrame(true);
- EXPECT_TRUE(panel->IsDrawingAttention());
+ panel1->FlashFrame(true);
+ EXPECT_TRUE(panel1->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention());
// Test that the attention is cleared when panel gets focus.
- panel->Activate();
- WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
- EXPECT_FALSE(panel->IsDrawingAttention());
+ panel1->Activate();
+ WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE);
+ EXPECT_FALSE(panel1->IsDrawingAttention());
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
- panel->Close();
+ panel1->Close();
+ panel2->Close();
}
IN_PROC_BROWSER_TEST_F(DetachedPanelBrowserTest, ClickTitlebar) {
diff --git a/chrome/browser/ui/panels/native_panel_cocoa.h b/chrome/browser/ui/panels/native_panel_cocoa.h
new file mode 100644
index 0000000..e974783
--- /dev/null
+++ b/chrome/browser/ui/panels/native_panel_cocoa.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2012 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_PANELS_NATIVE_PANEL_COCOA_H_
+#define CHROME_BROWSER_UI_PANELS_NATIVE_PANEL_COCOA_H_
+#pragma once
+
+#include "chrome/browser/ui/panels/native_panel.h"
+
+// Cocoa NativePanel interface used by the PanelWindowControllerCocoa class
+// as its C++ window shim. I wish I had a "friend @class" construct to make
+// this interface non-public.
+class NativePanelCocoa : public NativePanel {
+ public:
+ virtual ~NativePanelCocoa() {}
+
+ virtual Panel* panel() const = 0;
+
+ // Callback from cocoa panel window controller that native window was actually
+ // closed. The window may not close right away because of onbeforeunload
+ // handlers.
+ virtual void DidCloseNativeWindow() = 0;
+};
+
+#endif // CHROME_BROWSER_UI_PANELS_NATIVE_PANEL_H_
diff --git a/chrome/browser/ui/panels/old_panel.cc b/chrome/browser/ui/panels/old_panel.cc
new file mode 100644
index 0000000..cb2a754
--- /dev/null
+++ b/chrome/browser/ui/panels/old_panel.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 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/panels/old_panel.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/panels/panel_browser_window.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+OldPanel::OldPanel(Browser* browser,
+ const gfx::Size& min_size, const gfx::Size& max_size)
+ : Panel(browser->app_name(), min_size, max_size),
+ browser_(browser) {
+}
+
+OldPanel::~OldPanel() {}
+
+Browser* OldPanel::browser() const {
+ return browser_;
+}
+
+BrowserWindow* OldPanel::browser_window() const {
+ return panel_browser_window_.get();
+}
+
+CommandUpdater* OldPanel::command_updater() {
+ return browser_->command_updater();
+}
+
+Profile* OldPanel::profile() const {
+ return browser_->profile();
+}
+
+void OldPanel::Initialize(const gfx::Rect& bounds, Browser* browser) {
+ Panel::Initialize(bounds, browser);
+ panel_browser_window_.reset(
+ new PanelBrowserWindow(browser, this, native_panel()));
+}
+
+content::WebContents* OldPanel::WebContents() const {
+ return browser_->GetSelectedWebContents();
+}
+
+bool OldPanel::ShouldCloseWindow() {
+ return browser_->ShouldCloseWindow();
+}
+
+void OldPanel::OnWindowClosing() {
+ browser_->OnWindowClosing();
+}
+
+void OldPanel::ExecuteCommandWithDisposition(
+ int id, WindowOpenDisposition disposition) {
+ browser_->ExecuteCommandWithDisposition(id, disposition);
+}
+
+SkBitmap OldPanel::GetCurrentPageIcon() const {
+ return browser_->GetCurrentPageIcon();
+}
diff --git a/chrome/browser/ui/panels/old_panel.h b/chrome/browser/ui/panels/old_panel.h
new file mode 100644
index 0000000..83748fa9
--- /dev/null
+++ b/chrome/browser/ui/panels/old_panel.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 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_PANELS_OLD_PANEL_H_
+#define CHROME_BROWSER_UI_PANELS_OLD_PANEL_H_
+#pragma once
+
+#include "chrome/browser/ui/panels/panel.h"
+
+class Browser;
+class PanelBrowserWindow;
+
+// Temporary class during the refactor to override behavior in Panel
+// to provide legacy behavior. Will be deleted after refactor is complete.
+class OldPanel : public Panel {
+ public:
+ OldPanel(Browser* browser,
+ const gfx::Size& min_size, const gfx::Size& max_size);
+ virtual ~OldPanel();
+
+ // Overridden from Panel.
+ virtual Browser* browser() const OVERRIDE;
+ virtual BrowserWindow* browser_window() const OVERRIDE;
+ virtual CommandUpdater* command_updater() OVERRIDE;
+ virtual Profile* profile() const OVERRIDE;
+ virtual void Initialize(const gfx::Rect& bounds, Browser* browser) OVERRIDE;
+ virtual content::WebContents* WebContents() const OVERRIDE;
+ virtual bool ShouldCloseWindow() OVERRIDE;
+ virtual void OnWindowClosing() OVERRIDE;
+ virtual void ExecuteCommandWithDisposition(
+ int id,
+ WindowOpenDisposition disposition) OVERRIDE;
+ virtual SkBitmap GetCurrentPageIcon() const OVERRIDE;
+
+ private:
+ Browser* browser_; // Weak pointer. Owned by native panel.
+
+ // A BrowserWindow for the browser to interact with.
+ scoped_ptr<PanelBrowserWindow> panel_browser_window_;
+};
+
+#endif // CHROME_BROWSER_UI_PANELS_OLD_PANEL_H_
diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc
index 3ecad38..f396c8e 100644
--- a/chrome/browser/ui/panels/panel.cc
+++ b/chrome/browser/ui/panels/panel.cc
@@ -6,10 +6,9 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/panels/native_panel.h"
-#include "chrome/browser/ui/panels/panel_browser_window.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_strip.h"
#include "chrome/common/chrome_notification_types.h"
@@ -18,12 +17,15 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/rect.h"
using content::RenderViewHost;
-Panel::Panel(const gfx::Size& min_size, const gfx::Size& max_size)
- : panel_strip_(NULL),
+Panel::Panel(const std::string& app_name,
+ const gfx::Size& min_size, const gfx::Size& max_size)
+ : app_name_(app_name),
+ panel_strip_(NULL),
initialized_(false),
min_size_(min_size),
max_size_(max_size),
@@ -33,7 +35,8 @@ Panel::Panel(const gfx::Size& min_size, const gfx::Size& max_size)
in_preview_mode_(false),
native_panel_(NULL),
attention_mode_(USE_PANEL_ATTENTION),
- expansion_state_(EXPANDED) {
+ expansion_state_(EXPANDED),
+ command_updater_(this) {
}
Panel::~Panel() {
@@ -48,8 +51,6 @@ void Panel::Initialize(const gfx::Rect& bounds, Browser* browser) {
initialized_ = true;
full_size_ = bounds.size();
native_panel_ = CreateNativePanel(browser, this, bounds);
- panel_browser_window_.reset(
- new PanelBrowserWindow(browser, this, native_panel_));
}
void Panel::OnNativePanelClosed() {
@@ -62,15 +63,25 @@ PanelManager* Panel::manager() const {
}
Browser* Panel::browser() const {
- return native_panel_->GetPanelBrowser();
+ return NULL;
}
BrowserWindow* Panel::browser_window() const {
- return panel_browser_window_.get();
+ return NULL;
+}
+
+CommandUpdater* Panel::command_updater() {
+ return &command_updater_;
+}
+
+Profile* Panel::profile() const {
+ // TODO(jennb): implement.
+ return NULL;
}
content::WebContents* Panel::WebContents() const {
- return native_panel_->GetPanelBrowser()->GetSelectedWebContents();
+ // TODO(jennb): implement.
+ return NULL;
}
bool Panel::CanMinimize() const {
@@ -249,7 +260,7 @@ void Panel::SetBounds(const gfx::Rect& bounds) {
SetAutoResizable(false);
}
-// Close() may be called multiple times if the browser window is not ready to
+// Close() may be called multiple times if the panel window is not ready to
// close on the first attempt.
void Panel::Close() {
native_panel_->ClosePanel();
@@ -364,6 +375,20 @@ void Panel::EnableWebContentsAutoResize(content::WebContents* web_contents) {
content::Source<content::WebContents>(web_contents));
}
+void Panel::ExecuteCommandWithDisposition(int id,
+ WindowOpenDisposition disposition) {
+ // TODO(jennb): implement.
+}
+
+bool Panel::ExecuteCommandIfEnabled(int id) {
+ if (command_updater()->SupportsCommand(id) &&
+ command_updater()->IsCommandEnabled(id)) {
+ ExecuteCommandWithDisposition(id, CURRENT_TAB);
+ return true;
+ }
+ return false;
+}
+
void Panel::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -449,3 +474,42 @@ void Panel::OnPanelEndUserResizing() {
SetPreviewMode(false);
}
+bool Panel::ShouldCloseWindow() {
+ // TODO(jennb): implement
+ return true;
+}
+
+void Panel::OnWindowClosing() {
+ // TODO(jennb): implement
+}
+
+string16 Panel::GetWindowTitle() const {
+ content::WebContents* contents = WebContents();
+ string16 title;
+
+ // |contents| can be NULL during the window's creation.
+ if (contents) {
+ title = contents->GetTitle();
+ FormatTitleForDisplay(&title);
+ }
+
+ if (title.empty())
+ title = UTF8ToUTF16(app_name());
+
+ return title;
+}
+
+// static
+void Panel::FormatTitleForDisplay(string16* title) {
+ size_t current_index = 0;
+ size_t match_index;
+ while ((match_index = title->find(L'\n', current_index)) != string16::npos) {
+ title->replace(match_index, 1, string16());
+ current_index = match_index;
+ }
+}
+
+SkBitmap Panel::GetCurrentPageIcon() const {
+ // TODO(jennb): implement.
+ return SkBitmap();
+}
diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h
index b3b5323..0435285 100644
--- a/chrome/browser/ui/panels/panel.h
+++ b/chrome/browser/ui/panels/panel.h
@@ -6,8 +6,12 @@
#define CHROME_BROWSER_UI_PANELS_PANEL_H_
#pragma once
+#include <string>
+
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/string16.h"
+#include "chrome/browser/command_updater.h"
#include "chrome/browser/ui/base_window.h"
#include "chrome/browser/ui/panels/panel_constants.h"
#include "content/public/browser/notification_observer.h"
@@ -17,9 +21,10 @@
class Browser;
class BrowserWindow;
class NativePanel;
-class PanelBrowserWindow;
class PanelManager;
class PanelStrip;
+class Profile;
+class SkBitmap;
namespace content {
class WebContents;
@@ -35,6 +40,7 @@ class WebContents;
// - Invoke an appropriate PanelManager function to do stuff that might affect
// other Panels. For example deleting a panel would rearrange other panels.
class Panel : public BaseWindow,
+ public CommandUpdater::CommandUpdaterDelegate,
public content::NotificationObserver {
public:
enum ExpansionState {
@@ -62,9 +68,13 @@ class Panel : public BaseWindow,
// Returns the PanelManager associated with this panel.
PanelManager* manager() const;
+ const std::string& app_name() const { return app_name_; }
+ virtual CommandUpdater* command_updater();
+ virtual Profile* profile() const;
+
// Returns web contents of the panel, if any. There may be none if web
// contents have not been added to the panel yet.
- content::WebContents* WebContents() const;
+ virtual content::WebContents* WebContents() const;
void SetExpansionState(ExpansionState new_expansion_state);
@@ -108,6 +118,11 @@ class Panel : public BaseWindow,
virtual void FlashFrame(bool flash) OVERRIDE;
virtual bool IsAlwaysOnTop() const OVERRIDE;
+ // Overridden from CommandUpdater::CommandUpdaterDelegate:
+ virtual void ExecuteCommandWithDisposition(
+ int id,
+ WindowOpenDisposition disposition) OVERRIDE;
+
// content::NotificationObserver overrides.
virtual void Observe(int type,
const content::NotificationSource& source,
@@ -119,6 +134,8 @@ class Panel : public BaseWindow,
Panel* panel,
const gfx::Rect& bounds);
+ NativePanel* native_panel() const { return native_panel_; }
+
// Invoked when the native panel has detected a mouse click on the
// panel's titlebar, minimize or restore buttons. Behavior of the
// click may be modified as indicated by |modifier|.
@@ -134,9 +151,8 @@ class Panel : public BaseWindow,
void OnNativePanelClosed();
// Legacy accessors.
- Browser* browser() const;
- NativePanel* native_panel() const { return native_panel_; }
- BrowserWindow* browser_window() const;
+ virtual Browser* browser() const;
+ virtual BrowserWindow* browser_window() const;
// May be NULL if:
// * panel is newly created and has not been positioned yet.
@@ -169,7 +185,7 @@ class Panel : public BaseWindow,
// Panel must be initialized to be "fully created" and ready for use.
// Only called by PanelManager.
bool initialized() const { return initialized_; }
- void Initialize(const gfx::Rect& bounds, Browser* browser);
+ virtual void Initialize(const gfx::Rect& bounds, Browser* browser); // legacy
// This is different from BrowserWindow::SetBounds():
// * SetPanelBounds() is only called by PanelManager to manage its position.
@@ -238,6 +254,31 @@ class Panel : public BaseWindow,
void OnPanelStartUserResizing();
void OnPanelEndUserResizing();
+ // Gives beforeunload handlers the chance to cancel the close.
+ virtual bool ShouldCloseWindow();
+
+ // Invoked when the window containing us is closing. Performs the necessary
+ // cleanup.
+ virtual void OnWindowClosing();
+
+ // Executes a command if it's enabled.
+ // Returns true if the command is executed.
+ bool ExecuteCommandIfEnabled(int id);
+
+ // Gets the title of the window from the web contents.
+ string16 GetWindowTitle() const;
+
+ // Gets the Favicon of the web contents.
+ virtual SkBitmap GetCurrentPageIcon() const;
+
+ protected:
+ // Panel can only be created using PanelManager::CreatePanel() or subclass.
+ // |app_name| is the default title for Panels when the page content does not
+ // provide a title. For extensions, this is usually the application name
+ // generated from the extension id.
+ Panel(const std::string& app_name,
+ const gfx::Size& min_size, const gfx::Size& max_size);
+
private:
friend class PanelManager;
friend class PanelBrowserTest;
@@ -249,14 +290,16 @@ class Panel : public BaseWindow,
CUSTOM_MAX_SIZE
};
- // Panel can only be created using PanelManager::CreatePanel().
- explicit Panel(const gfx::Size& min_size, const gfx::Size& max_size);
-
// Configures the renderer for auto resize (if auto resize is enabled).
void ConfigureAutoResize(content::WebContents* web_contents);
- // A BrowserWindow for the browser to interact with.
- scoped_ptr<PanelBrowserWindow> panel_browser_window_;
+ // Prepares a title string for display (removes embedded newlines, etc).
+ static void FormatTitleForDisplay(string16* title);
+
+ // The application name that is also the name of the window when the
+ // page content does not provide a title.
+ // This name should be set when the panel is created.
+ const std::string& app_name_;
// Current collection of panels to which this panel belongs. This determines
// the panel's screen layout.
@@ -297,6 +340,9 @@ class Panel : public BaseWindow,
ExpansionState expansion_state_;
+ // The CommandUpdater manages the window commands.
+ CommandUpdater command_updater_;
+
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(Panel);
diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc
index a4dfadd..78b7cd6 100644
--- a/chrome/browser/ui/panels/panel_browser_frame_view.cc
+++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc
@@ -608,7 +608,7 @@ bool PanelBrowserFrameView::UsingDefaultTheme(PaintState paint_state) const {
return true;
ThemeService* theme_service = ThemeServiceFactory::GetForProfile(
- panel_browser_view_->browser()->profile());
+ panel_browser_view_->panel()->profile());
return theme_service->UsingDefaultTheme();
}
diff --git a/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc b/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
index 5ccb1ef..83b8e20 100644
--- a/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
+++ b/chrome/browser/ui/panels/panel_browser_titlebar_gtk.cc
@@ -77,8 +77,7 @@ void PanelBrowserTitlebarGtk::UpdateButtonBackground(CustomDrawButton* button) {
void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() {
DCHECK(app_mode_title());
- std::string title =
- UTF16ToUTF8(browser_window_->browser()->GetWindowTitleForCurrentTab());
+ std::string title = UTF16ToUTF8(browser_window_->panel()->GetWindowTitle());
// Add the markup to show the title as bold.
gchar* escaped_title = g_markup_escape_text(title.c_str(), -1);
diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.h b/chrome/browser/ui/panels/panel_browser_window_cocoa.h
index c51c304..a891d16 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa.h
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.h
@@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
-#include "chrome/browser/ui/panels/native_panel.h"
+#include "chrome/browser/ui/panels/native_panel_cocoa.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -22,7 +22,7 @@ class Panel;
// Bridges between C++ and the Cocoa NSWindow. Cross-platform code will
// interact with this object when it needs to manipulate the window.
-class PanelBrowserWindowCocoa : public NativePanel,
+class PanelBrowserWindowCocoa : public NativePanelCocoa,
public TabStripModelObserver,
public content::NotificationObserver {
public:
@@ -87,18 +87,9 @@ class PanelBrowserWindowCocoa : public NativePanel,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- Panel* panel() { return panel_.get(); }
-
- // Callback from PanelWindowControllerCocoa that native window was actually
- // closed. The window may not close right away because of onbeforeunload
- // handlers.
- void DidCloseNativeWindow();
-
- // A Panel window is allowed to become the key window if the activation
- // request came from the browser.
- bool ActivationRequestedByBrowser() {
- return activation_requested_by_browser_;
- }
+ // Overridden from NativePanelCocoa.
+ virtual Panel* panel() const OVERRIDE;
+ virtual void DidCloseNativeWindow() OVERRIDE;
private:
friend class PanelBrowserWindowCocoaTest;
@@ -131,12 +122,6 @@ class PanelBrowserWindowCocoa : public NativePanel,
bool has_find_bar_; // Find bar should only be created once per panel.
NSInteger attention_request_id_; // identifier from requestUserAttention.
- // Allow a panel to become key if activated via browser logic, as opposed
- // to by default system selection. The system will prefer a panel
- // window over other application windows due to panels having a higher
- // priority NSWindowLevel, so we distinguish between the two scenarios.
- bool activation_requested_by_browser_;
-
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(PanelBrowserWindowCocoa);
diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
index 2b59665..e9ceeed 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
@@ -4,7 +4,6 @@
#include "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
-#include "base/auto_reset.h"
#include "base/logging.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
@@ -51,9 +50,8 @@ PanelBrowserWindowCocoa::PanelBrowserWindowCocoa(Browser* browser,
bounds_(bounds),
is_shown_(false),
has_find_bar_(false),
- attention_request_id_(0),
- activation_requested_by_browser_(false) {
- controller_ = [[PanelWindowControllerCocoa alloc] initWithBrowserWindow:this];
+ attention_request_id_(0) {
+ controller_ = [[PanelWindowControllerCocoa alloc] initWithPanel:this];
browser_->tab_strip_model()->AddObserver(this);
registrar_.Add(
this,
@@ -144,8 +142,7 @@ void PanelBrowserWindowCocoa::ActivatePanel() {
if (!is_shown_)
return;
- AutoReset<bool> pin(&activation_requested_by_browser_, true);
- [BrowserWindowUtils activateWindowForController:controller_];
+ [controller_ activate];
}
void PanelBrowserWindowCocoa::DeactivatePanel() {
@@ -298,6 +295,10 @@ void PanelBrowserWindowCocoa::UpdatePanelMinimizeRestoreButtonVisibility() {
[controller_ updateTitleBarMinimizeRestoreButtonVisibility];
}
+Panel* PanelBrowserWindowCocoa::panel() const {
+ return panel_.get();
+}
+
void PanelBrowserWindowCocoa::DidCloseNativeWindow() {
DCHECK(!isClosed());
panel_->OnNativePanelClosed();
diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm
index e8bd96e..651253e 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa_unittest.mm
@@ -11,6 +11,7 @@
#include "base/debug/debugger.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
+#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" // IDC_*
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
@@ -373,17 +374,20 @@ TEST_F(PanelBrowserWindowCocoaTest, ThemeProvider) {
}
TEST_F(PanelBrowserWindowCocoaTest, SetTitle) {
- Panel* panel = CreateTestPanel("Test Panel");
+ NSString *appName = @"Test Panel";
+ Panel* panel = CreateTestPanel(base::SysNSStringToUTF8(appName));
ASSERT_TRUE(panel);
PanelBrowserWindowCocoa* native_window =
static_cast<PanelBrowserWindowCocoa*>(panel->native_panel());
ASSERT_TRUE(native_window);
NSString* previousTitle = [[native_window->controller_ window] title];
+ EXPECT_NSNE(appName, previousTitle);
[native_window->controller_ updateTitleBar];
chrome::testing::NSRunLoopRunAllPending();
- EXPECT_NSEQ(@"Untitled", [[native_window->controller_ window] title]);
- EXPECT_NSNE([[native_window->controller_ window] title], previousTitle);
+ NSString* currentTitle = [[native_window->controller_ window] title];
+ EXPECT_NSEQ(appName, currentTitle);
+ EXPECT_NSNE(currentTitle, previousTitle);
ClosePanelAndWait(panel);
}
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index 2b943eb..0ac8e14 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -869,7 +869,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) {
EXPECT_TRUE(native_panel_testing->VerifyActiveState(true));
}
// TODO(jianli): To be enabled for other platforms.
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN)
#define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple
#else
#define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple
@@ -972,17 +972,19 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher();
PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher);
- CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE);
- Panel* panel = CreatePanelWithParams(params);
- NativePanel* native_panel = panel->native_panel();
+ // Create 2 panels so we end up with an inactive panel that can
+ // be made to draw attention.
+ Panel* panel = CreatePanel("test panel1");
+ Panel* panel2 = CreatePanel("test panel2");
+ Panel* panel3 = CreatePanel("test panel2");
+
scoped_ptr<NativePanelTesting> native_panel_testing(
- NativePanelTesting::Create(native_panel));
+ NativePanelTesting::Create(panel->native_panel()));
// Test that the attention is drawn and the title-bar is brought up when the
// minimized panel is drawing attention.
- panel->SetExpansionState(Panel::MINIMIZED);
- WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
- EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
+ panel->Minimize();
+ WaitForExpansionStateChanged(panel, Panel::MINIMIZED);
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
@@ -991,9 +993,11 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
// Test that we cannot bring up other minimized panel if the mouse is over
// the panel that draws attension.
+ panel2->Minimize();
gfx::Point hover_point(panel->GetBounds().origin());
MoveMouse(hover_point);
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
+ EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state());
// Test that we cannot bring down the panel that is drawing the attention.
hover_point.set_y(hover_point.y() - 200);
@@ -1009,6 +1013,8 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) {
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
+ panel2->Close();
+ panel3->Close();
}
// Verify that minimized state of a panel is correct after draw attention
@@ -1100,15 +1106,14 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) {
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
- CreatePanelParams params("Initially active", gfx::Rect(), SHOW_AS_ACTIVE);
- Panel* panel = CreatePanelWithParams(params);
+ // Create 2 panels so we end up with an inactive panel that can
+ // be made to draw attention.
+ Panel* panel = CreatePanel("test panel1");
+ Panel* panel2 = CreatePanel("test panel2");
+
scoped_ptr<NativePanelTesting> native_panel_testing(
NativePanelTesting::Create(panel->native_panel()));
- // Deactivate the panel.
- panel->Deactivate();
- WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
-
panel->FlashFrame(true);
EXPECT_TRUE(panel->IsDrawingAttention());
MessageLoop::current()->RunAllPending();
@@ -1122,6 +1127,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) {
EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention());
panel->Close();
+ panel2->Close();
}
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
@@ -1180,7 +1186,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) {
IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
MinimizeImmediatelyAfterRestore) {
- CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_ACTIVE);
+ CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE);
Panel* panel = CreatePanelWithParams(params);
scoped_ptr<NativePanelTesting> native_panel_testing(
NativePanelTesting::Create(panel->native_panel()));
@@ -1190,15 +1196,15 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
WaitForPanelActiveState(panel, SHOW_AS_INACTIVE);
EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
- panel->Activate();
+ panel->Restore();
MessageLoop::current()->RunAllPending();
- WaitForPanelActiveState(panel, SHOW_AS_ACTIVE);
- EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
+ WaitForExpansionStateChanged(panel, Panel::EXPANDED);
// Verify that minimizing a panel right after expansion works.
panel->Minimize();
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
+ WaitForExpansionStateChanged(panel, Panel::MINIMIZED);
+
panel->Close();
}
diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc
index 957faba..eaa6a76b6 100644
--- a/chrome/browser/ui/panels/panel_manager.cc
+++ b/chrome/browser/ui/panels/panel_manager.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/panels/detached_panel_strip.h"
#include "chrome/browser/ui/panels/docked_panel_strip.h"
+#include "chrome/browser/ui/panels/old_panel.h"
#include "chrome/browser/ui/panels/panel_drag_controller.h"
#include "chrome/browser/ui/panels/panel_mouse_watcher.h"
#include "chrome/browser/ui/panels/panel_resize_controller.h"
@@ -173,7 +174,7 @@ Panel* PanelManager::CreatePanel(Browser* browser) {
panel_size);
// Create the (legacy) panel.
- Panel* panel = new Panel(min_size, max_size);
+ Panel* panel = new OldPanel(browser, min_size, max_size);
panel->Initialize(bounds, browser);
// Auto resizable feature is enabled only if no initial size is requested.
diff --git a/chrome/browser/ui/panels/panel_window_controller_cocoa.h b/chrome/browser/ui/panels/panel_window_controller_cocoa.h
index 8b3080b..29447d4 100644
--- a/chrome/browser/ui/panels/panel_window_controller_cocoa.h
+++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.h
@@ -23,7 +23,7 @@
#include "chrome/browser/ui/panels/panel.h"
@class FindBarCocoaController;
-class PanelBrowserWindowCocoa;
+class NativePanelCocoa;
@class PanelTitlebarViewCocoa;
@interface PanelWindowCocoaImpl : ChromeBrowserWindow {
@@ -36,7 +36,7 @@ class PanelBrowserWindowCocoa;
BrowserCommandExecutor> {
@private
IBOutlet PanelTitlebarViewCocoa* titlebar_view_;
- scoped_ptr<PanelBrowserWindowCocoa> windowShim_;
+ scoped_ptr<NativePanelCocoa> windowShim_;
scoped_nsobject<NSString> pendingWindowTitle_;
scoped_nsobject<TabContentsController> contentsController_;
NSViewAnimation* boundsAnimation_; // Lifetime controlled manually, needs
@@ -46,11 +46,16 @@ class PanelBrowserWindowCocoa;
BOOL playingMinimizeAnimation_;
float animationStopToShowTitlebarOnly_;
BOOL canBecomeKeyWindow_;
+ // Allow a panel to become key if activated via Panel logic, as opposed
+ // to by default system selection. The system will prefer a panel
+ // window over other application windows due to panels having a higher
+ // priority NSWindowLevel, so we distinguish between the two scenarios.
+ BOOL activationRequestedByPanel_;
scoped_nsobject<NSView> overlayView_;
}
-// Load the browser window nib and do any Cocoa-specific initialization.
-- (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window;
+// Load the window nib and do any Cocoa-specific initialization.
+- (id)initWithPanel:(NativePanelCocoa*)window;
- (ui::ThemeProvider*)themeProvider;
- (ThemedWindowStyle)themedWindowStyle;
@@ -123,7 +128,8 @@ class PanelBrowserWindowCocoa;
- (BOOL)isAnimatingBounds;
-// Removes the Key status from the panel to some other window.
+// Sets/Removes the Key status from the panel to some other window.
+- (void)activate;
- (void)deactivate;
// Changes the canBecomeKeyWindow state
@@ -136,8 +142,8 @@ class PanelBrowserWindowCocoa;
// are not un-minimized when another panel is minimized.
- (BOOL)canBecomeKeyWindow;
-// Returns true if browser window requested activation of the window.
-- (BOOL)activationRequestedByBrowser;
+// Returns true if Panel requested activation of the window.
+- (BOOL)activationRequestedByPanel;
- (void)ensureFullyVisible;
diff --git a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm
index 2099d49..5741803 100644
--- a/chrome/browser/ui/panels/panel_window_controller_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_window_controller_cocoa.mm
@@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
+#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/mac_util.h"
@@ -16,9 +17,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#import "chrome/browser/ui/cocoa/event_utils.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
@@ -27,8 +25,8 @@
#import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h"
#import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
#import "chrome/browser/ui/cocoa/tabs/throbber_view.h"
+#include "chrome/browser/ui/panels/native_panel_cocoa.h"
#include "chrome/browser/ui/panels/panel_bounds_animation.h"
-#include "chrome/browser/ui/panels/panel_browser_window_cocoa.h"
#include "chrome/browser/ui/panels/panel_constants.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#include "chrome/browser/ui/panels/panel_strip.h"
@@ -39,6 +37,7 @@
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "grit/ui_resources_standard.h"
+#include "skia/ext/skia_utils_mac.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/mac/nsimage_cache.h"
@@ -105,7 +104,7 @@ enum {
// This prevents the system from always preferring a Panel window due
// to its higher priority NSWindowLevel when selecting a window to make key.
return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) ||
- [controller activationRequestedByBrowser] ||
+ [controller activationRequestedByPanel] ||
[app isCyclingWindows] ||
[app previousKeyWindow] == self ||
[[app windows] count] == static_cast<NSUInteger>([controller numPanels]);
@@ -430,13 +429,14 @@ enum {
@implementation PanelWindowControllerCocoa
-- (id)initWithBrowserWindow:(PanelBrowserWindowCocoa*)window {
+- (id)initWithPanel:(NativePanelCocoa*)window {
NSString* nibpath =
[base::mac::FrameworkBundle() pathForResource:@"Panel" ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
windowShim_.reset(window);
animateOnBoundsChange_ = YES;
canBecomeKeyWindow_ = YES;
+ activationRequestedByPanel_ = NO;
contentsController_.reset(
[[TabContentsController alloc] initWithContents:nil]);
}
@@ -445,12 +445,12 @@ enum {
- (ui::ThemeProvider*)themeProvider {
return ThemeServiceFactory::GetForProfile(
- windowShim_->GetPanelBrowser()->profile());
+ windowShim_->panel()->profile());
}
- (ThemedWindowStyle)themedWindowStyle {
ThemedWindowStyle style = THEMED_POPUP;
- if (windowShim_->GetPanelBrowser()->profile()->IsOffTheRecord())
+ if (windowShim_->panel()->profile()->IsOffTheRecord())
style |= THEMED_INCOGNITO;
return style;
}
@@ -479,7 +479,7 @@ enum {
// Set initial size of the window to match the size of the panel to give
// the renderer the proper size to work with earlier, avoiding a resize
// after the window is revealed.
- gfx::Rect panelBounds = windowShim_->GetPanelBounds();
+ gfx::Rect panelBounds = windowShim_->panel()->GetBounds();
NSRect frame = [window frame];
frame.size.width = panelBounds.width();
frame.size.height = panelBounds.height();
@@ -555,7 +555,7 @@ enum {
- (void)updateTitleBar {
NSString* newTitle = base::SysUTF16ToNSString(
- windowShim_->GetPanelBrowser()->GetWindowTitleForCurrentTab());
+ windowShim_->panel()->GetWindowTitle());
pendingWindowTitle_.reset(
[BrowserWindowUtils scheduleReplaceOldTitle:pendingWindowTitle_.get()
withNewTitle:newTitle
@@ -577,10 +577,11 @@ enum {
icon = [ThrobberView filmstripThrobberViewWithFrame:iconFrame
image:iconImage];
} else {
- NSImage* iconImage = mac::FaviconForTabContents(
- windowShim_->GetPanelBrowser()->GetSelectedTabContentsWrapper());
- if (!iconImage)
- iconImage = gfx::GetCachedImageWithName(@"nav.pdf");
+ SkBitmap bitmap = windowShim_->panel()->GetCurrentPageIcon();
+ NSImage* iconImage = bitmap.isNull() ?
+ gfx::GetCachedImageWithName(@"nav.pdf") :
+ gfx::SkBitmapToNSImageWithColorSpace(bitmap,
+ base::mac::GetSystemColorSpace());
NSImageView* iconView =
[[[NSImageView alloc] initWithFrame:iconFrame] autorelease];
[iconView setImage:iconImage];
@@ -644,7 +645,7 @@ enum {
action == @selector(commandDispatchUsingKeyModifiers:)) {
NSInteger tag = [item tag];
CommandUpdater* command_updater =
- windowShim_->GetPanelBrowser()->command_updater();
+ windowShim_->panel()->command_updater();
if (command_updater->SupportsCommand(tag)) {
enable = command_updater->IsCommandEnabled(tag);
// Disable commands that do not apply to Panels.
@@ -671,12 +672,13 @@ enum {
}
// Called when the user picks a menu or toolbar item when this window is key.
-// Calls through to the browser object to execute the command. This assumes that
+// Calls through to the panel object to execute the command. This assumes that
// the command is supported and doesn't check, otherwise it would have been
// disabled in the UI in validateUserInterfaceItem:.
- (void)commandDispatch:(id)sender {
DCHECK(sender);
- windowShim_->GetPanelBrowser()->ExecuteCommand([sender tag]);
+ windowShim_->panel()->ExecuteCommandWithDisposition([sender tag],
+ CURRENT_TAB);
}
// Same as |-commandDispatch:|, but executes commands using a disposition
@@ -687,12 +689,12 @@ enum {
WindowOpenDisposition disposition =
event_utils::WindowOpenDispositionFromNSEventWithFlags(
event, [event modifierFlags]);
- windowShim_->GetPanelBrowser()->ExecuteCommandWithDisposition(
+ windowShim_->panel()->ExecuteCommandWithDisposition(
[sender tag], disposition);
}
- (void)executeCommand:(int)command {
- windowShim_->GetPanelBrowser()->ExecuteCommandIfEnabled(command);
+ windowShim_->panel()->ExecuteCommandIfEnabled(command);
}
// Handler for the custom Close button.
@@ -715,40 +717,38 @@ enum {
}
// Called when the user wants to close the panel or from the shutdown process.
-// The Browser object is in control of whether or not we're allowed to close. It
+// The Panel object is in control of whether or not we're allowed to close. It
// may defer closing due to several states, such as onbeforeUnload handlers
-// needing to be fired. If closing is deferred, the Browser will handle the
+// needing to be fired. If closing is deferred, the Panel will handle the
// processing required to get us to the closing state and (by watching for
-// all the tabs going away) will again call to close the window when it's
+// the web content going away) will again call to close the window when it's
// finally ready.
// This callback is only called if the standard Close button is enabled in XIB.
- (BOOL)windowShouldClose:(id)sender {
- Browser* browser = windowShim_->GetPanelBrowser();
+ Panel* panel = windowShim_->panel();
// Give beforeunload handlers the chance to cancel the close before we hide
// the window below.
- if (!browser->ShouldCloseWindow())
+ if (!panel->ShouldCloseWindow())
return NO;
- if (!browser->tab_strip_model()->empty()) {
+ if (panel->WebContents()) {
// Terminate any playing animations.
[self terminateBoundsAnimation];
animateOnBoundsChange_ = NO;
- // Tab strip isn't empty. Make browser to close all the tabs, allowing the
- // renderer to shut down and call us back again.
- // The tab strip of Panel is not visible and contains only one tab but
- // it still has to be closed.
- browser->OnWindowClosing();
+ // Make panel close the web content, allowing the renderer to shut down
+ // and call us back again.
+ panel->OnWindowClosing();
return NO;
}
- // The tab strip is empty, it's ok to close the window.
+ // No web content; it's ok to close the window.
return YES;
}
// When windowShouldClose returns YES (or if controller receives direct 'close'
// signal), window will be unconditionally closed. Clean up.
- (void)windowWillClose:(NSNotification*)notification {
- DCHECK(windowShim_->GetPanelBrowser()->tab_strip_model()->empty());
+ DCHECK(!windowShim_->panel()->WebContents());
// Avoid callbacks from a nonblocking animation in progress, if any.
[self terminateBoundsAnimation];
windowShim_->DidCloseNativeWindow();
@@ -833,8 +833,8 @@ enum {
// method, see below for more details.
if (distanceY > 0 &&
windowShim_->panel()->expansion_state() == Panel::MINIMIZED) {
- animationStopToShowTitlebarOnly_ =
- 1.0 - (windowShim_->TitleOnlyHeight() - NSHeight(frame)) / distanceY;
+ animationStopToShowTitlebarOnly_ = 1.0 -
+ (windowShim_->panel()->TitleOnlyHeight() - NSHeight(frame)) / distanceY;
if (animationStopToShowTitlebarOnly_ > 0.7) { // Relatively big movement.
playingMinimizeAnimation_ = YES;
duration = 1.5;
@@ -908,8 +908,6 @@ enum {
// whether it's refactoring more things into BrowserWindowUtils or making a
// common base controller for browser windows.
- (void)windowDidBecomeKey:(NSNotification*)notification {
- BrowserList::SetLastActive(windowShim_->GetPanelBrowser());
-
// We need to activate the controls (in the "WebView"). To do this, get the
// selected WebContents's RenderWidgetHostView and tell it to activate.
if (WebContents* contents = [contentsController_ webContents]) {
@@ -940,17 +938,21 @@ enum {
windowShim_->panel()->OnActiveStateChanged(false);
}
+- (void)activate {
+ AutoReset<BOOL> pin(&activationRequestedByPanel_, true);
+ [BrowserWindowUtils activateWindowForController:self];
+}
+
- (void)deactivate {
if (![[self window] isMainWindow])
return;
- BrowserWindow* browser_window =
- windowShim_->panel()->manager()->GetNextBrowserWindowToActivate(
- windowShim_->GetPanelBrowser());
- if (browser_window)
- browser_window->Activate();
- else
- [NSApp deactivate];
+ // Cocoa does not support deactivating a window, so we deactivate the app.
+ [NSApp deactivate];
+
+ // Deactivating the app does not trigger windowDidResignKey so the panel
+ // doesn't know it's active status has changed. Let the window know.
+ windowShim_->panel()->OnActiveStateChanged(false);
}
- (void)preventBecomingKeyWindow:(BOOL)prevent {
@@ -982,8 +984,8 @@ enum {
return windowShim_->panel()->manager()->num_panels();
}
-- (BOOL)activationRequestedByBrowser {
- return windowShim_->ActivationRequestedByBrowser();
+- (BOOL)activationRequestedByPanel {
+ return activationRequestedByPanel_;
}
- (void)updateWindowLevel {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index df4fdfb..4502a12 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3137,6 +3137,9 @@
'browser/ui/panels/docked_panel_strip.cc',
'browser/ui/panels/docked_panel_strip.h',
'browser/ui/panels/native_panel.h',
+ 'browser/ui/panels/native_panel_cocoa.h',
+ 'browser/ui/panels/old_panel.cc',
+ 'browser/ui/panels/old_panel.h',
'browser/ui/panels/panel.cc',
'browser/ui/panels/panel.h',
'browser/ui/panels/panel_bounds_animation.cc',