diff options
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/constrained_window_mac.h | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/constrained_window_mac.mm | 23 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.h | 17 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 53 |
6 files changed, 32 insertions, 81 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index ed2b18b..9a15e39 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -209,12 +209,7 @@ class TabStripModelObserverBridge; - (GTMWindowSheetController*)sheetController; // Requests that |window| is opened as a per-tab sheet to the current tab. -// Returns YES if the window became the active per-tab sheet of the current tab, -// or NO if the current tab already has a per-tab sheet. If this returns NO, -// the window's |Realize()| method will be called again when the curren sheet -// disappears. The window should then call |attachConstrainedWindow:| again. -- (BOOL)attachConstrainedWindow:(ConstrainedWindowMac*)window; - +- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window; // Closes the tab sheet |window| and potentially shows the next sheet in the // tab's sheet queue. - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index d8be276..51d1ced 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -385,8 +385,8 @@ willPositionSheet:(NSWindow*)sheet afterDelay:0]; } -- (BOOL)attachConstrainedWindow:(ConstrainedWindowMac*)window { - return [tabStripController_ attachConstrainedWindow:window]; +- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { + [tabStripController_ attachConstrainedWindow:window]; } - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { diff --git a/chrome/browser/cocoa/constrained_window_mac.h b/chrome/browser/cocoa/constrained_window_mac.h index 83331c7..0fd315d 100644 --- a/chrome/browser/cocoa/constrained_window_mac.h +++ b/chrome/browser/cocoa/constrained_window_mac.h @@ -117,6 +117,7 @@ class ConstrainedWindowMac : public ConstrainedWindow { virtual ~ConstrainedWindowMac(); // Overridden from ConstrainedWindow: + virtual void ShowConstrainedWindow(); virtual void CloseConstrainedWindow(); // Returns the TabContents that constrains this Constrained Window. @@ -125,12 +126,9 @@ class ConstrainedWindowMac : public ConstrainedWindow { // Returns the window's delegate. ConstrainedWindowMacDelegate* delegate() { return delegate_; } - // Tells |controller_| that the sheet would like to be displayed. + // Makes the constrained window visible, if it is not yet visible. void Realize(BrowserWindowController* controller); - // Called by |controller_| to inform the sheet that it now is visible. - void SetVisible(); - private: friend class ConstrainedWindow; @@ -146,6 +144,9 @@ class ConstrainedWindowMac : public ConstrainedWindow { // Controller of the window that contains this sheet. BrowserWindowController* controller_; + // Stores if |ShowConstrainedWindow()| was called. + bool should_be_visible_; + DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowMac); }; diff --git a/chrome/browser/cocoa/constrained_window_mac.mm b/chrome/browser/cocoa/constrained_window_mac.mm index ad090a8..eec4dba 100644 --- a/chrome/browser/cocoa/constrained_window_mac.mm +++ b/chrome/browser/cocoa/constrained_window_mac.mm @@ -46,10 +46,16 @@ ConstrainedWindowMac::ConstrainedWindowMac( TabContents* owner, ConstrainedWindowMacDelegate* delegate) : owner_(owner), delegate_(delegate), - controller_(nil) { + controller_(nil), + should_be_visible_(false) { DCHECK(owner); DCHECK(delegate); +} + +ConstrainedWindowMac::~ConstrainedWindowMac() {} +void ConstrainedWindowMac::ShowConstrainedWindow() { + should_be_visible_ = true; // The TabContents only has a native window if it is currently visible. In // this case, open the sheet now. Else, Realize() will be called later, when // our tab becomes visible. @@ -61,8 +67,6 @@ ConstrainedWindowMac::ConstrainedWindowMac( } } -ConstrainedWindowMac::~ConstrainedWindowMac() {} - void ConstrainedWindowMac::CloseConstrainedWindow() { // Note: controller_ can be `nil` here if the sheet was never realized. That's // ok. @@ -74,6 +78,9 @@ void ConstrainedWindowMac::CloseConstrainedWindow() { } void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { + if (!should_be_visible_) + return; + if (controller_ != nil) { DCHECK(controller_ == controller); return; @@ -82,13 +89,7 @@ void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { // Remember the controller we're adding ourselves to, so that we can later // remove us from it. - if ([controller attachConstrainedWindow:this]) - controller_ = controller; -} - -void ConstrainedWindowMac::SetVisible() { - // Only notify the delegate that the sheet is open after the sheet appeared - // on screen (as opposed to when the sheet was added to the current tab's - // sheet queue). + controller_ = controller; + [controller_ attachConstrainedWindow:this]; delegate_->set_sheet_open(true); } diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index f5f8d9d..8bc3b00 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -7,9 +7,6 @@ #import <Cocoa/Cocoa.h> -#include <deque> -#include <map> - #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" #import "chrome/browser/cocoa/tab_controller_target.h" @@ -53,7 +50,7 @@ class ToolbarModel; scoped_ptr<TabStripModelObserverBridge> bridge_; Browser* browser_; // weak TabStripModel* tabStripModel_; // weak - + // Access to the TabContentsControllers (which own the parent view // for the toolbar and associated tab contents) given an index. Call // |indexFromModelIndex:| to convert a |tabStripModel_| index to a @@ -110,12 +107,6 @@ class ToolbarModel; // Is the mouse currently inside the strip; BOOL mouseInside_; - - // GTMWindowSheetController supports only one per-tab sheet at a time. - // Thus, keep a queue of sheets for every tab. The first element in the queue - // is the currently visible sheet, and when this sheet is closed, the next - // sheet in the queue will be shown. - std::map<NSView*, std::deque<ConstrainedWindowMac*> > constrainedWindows_; } // Initialize the controller with a view and browser that contains @@ -192,9 +183,9 @@ class ToolbarModel; // Returns the currently active TabContentsController. - (TabContentsController*)activeTabContentsController; -// See comments in browser_window_controller.h for documentation about these -// functions. -- (BOOL)attachConstrainedWindow:(ConstrainedWindowMac*)window; + // See comments in browser_window_controller.h for documentation about these + // functions. +- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window; - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window; - (void)updateDevToolsForContents:(TabContents*)contents; diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 14eb3c7..8c2eac0 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -417,13 +417,11 @@ private: DCHECK(newTab); if (newTab) { TabContents::ConstrainedWindowList::iterator it, end; - it = newTab->constrained_window_begin(); end = newTab->constrained_window_end(); + NSWindowController* controller = [[newView window] windowController]; + DCHECK([controller isKindOfClass:[BrowserWindowController class]]); - // GTMWindowSheetController supports only one sheet at a time. - if (it != end) { - NSWindowController* controller = [[newView window] windowController]; - DCHECK([controller isKindOfClass:[BrowserWindowController class]]); + for (it = newTab->constrained_window_begin(); it != end; ++it) { ConstrainedWindow* constrainedWindow = *it; static_cast<ConstrainedWindowMac*>(constrainedWindow)->Realize( static_cast<BrowserWindowController*>(controller)); @@ -1637,7 +1635,7 @@ private: if (modelIndex < 0) return nil; NSInteger index = [self indexFromModelIndex:modelIndex]; - if (index < 0 || + if (index < 0 || index >= (NSInteger)[tabContentsArray_ count]) return nil; return [tabContentsArray_ objectAtIndex:index]; @@ -1656,7 +1654,7 @@ private: tabStripModel_->SelectTabContentsAt(index, false /* not a user gesture */); } -- (BOOL)attachConstrainedWindow:(ConstrainedWindowMac*)window { +- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { // TODO(thakis, avi): Figure out how to make this work when tabs are dragged // out or if fullscreen mode is toggled. @@ -1669,6 +1667,7 @@ private: // to pass it to the sheet controller here. NSView* tabContentsView = [[window->owner()->GetNativeView() superview] superview]; + window->delegate()->RunSheet([self sheetController], tabContentsView); // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets // between windows. Until then, we have to prevent having to move a tabsheet @@ -1680,23 +1679,8 @@ private: DCHECK(controller != nil); DCHECK(index >= 0); if (index >= 0) { - NSView* tab = [self viewAtIndex:index]; - [controller setTab:tab isDraggable:NO]; - - std::deque<ConstrainedWindowMac*>& windows = constrainedWindows_[tab]; - std::deque<ConstrainedWindowMac*>::iterator it = - find(windows.begin(), windows.end(), window); - if (it == windows.end()) - constrainedWindows_[tab].push_back(window); - - if (constrainedWindows_[tab].size() == 1) { - [controller setTab:tab isDraggable:NO]; - window->SetVisible(); - window->delegate()->RunSheet([self sheetController], tabContentsView); - return YES; - } + [controller setTab:[self viewAtIndex:index] isDraggable:NO]; } - return NO; } - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { @@ -1712,28 +1696,7 @@ private: (BrowserWindowController*)[[switchView_ window] windowController]; DCHECK(index >= 0); if (index >= 0) { - NSView* tab = [self viewAtIndex:index]; - - std::deque<ConstrainedWindowMac*>& windows = constrainedWindows_[tab]; - std::deque<ConstrainedWindowMac*>::iterator it = - find(windows.begin(), windows.end(), window); - DCHECK(it != windows.end()); - - bool removedVisibleSheet = it == windows.begin(); - - if (it != windows.end()) - windows.erase(it); - - if (windows.size() == 0) { - [controller setTab:tab isDraggable:YES]; - constrainedWindows_.erase(tab); - } else if (removedVisibleSheet && tab == [self selectedTabView]) { - // Show next sheet - NSWindowController* controller = [[tab window] windowController]; - DCHECK([controller isKindOfClass:[BrowserWindowController class]]); - windows.front()->Realize( - static_cast<BrowserWindowController*>(controller)); - } + [controller setTab:[self viewAtIndex:index] isDraggable:YES]; } } |