Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 23 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 24 #include "chrome/browser/fullscreen.h" | 24 #include "chrome/browser/fullscreen.h" |
| 25 #include "chrome/browser/profiles/avatar_menu.h" | 25 #include "chrome/browser/profiles/avatar_menu.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/profiles/profile_info_cache.h" | 27 #include "chrome/browser/profiles/profile_info_cache.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/browser/profiles/profiles_state.h" | 29 #include "chrome/browser/profiles/profiles_state.h" |
| 30 #include "chrome/browser/themes/theme_service.h" | 30 #include "chrome/browser/themes/theme_service.h" |
| 31 #include "chrome/browser/themes/theme_service_factory.h" | 31 #include "chrome/browser/themes/theme_service_factory.h" |
| 32 #include "chrome/browser/translate/chrome_translate_client.h" | 32 #include "chrome/browser/translate/chrome_translate_client.h" |
| 33 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" | |
| 33 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 34 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
| 34 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 35 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 35 #include "chrome/browser/ui/browser.h" | 36 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_command_controller.h" | 37 #include "chrome/browser/ui/browser_command_controller.h" |
| 37 #include "chrome/browser/ui/browser_commands.h" | 38 #include "chrome/browser/ui/browser_commands.h" |
| 39 #include "chrome/browser/ui/browser_dialogs.h" | |
| 38 #include "chrome/browser/ui/browser_instant_controller.h" | 40 #include "chrome/browser/ui/browser_instant_controller.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/browser_window_state.h" | 42 #include "chrome/browser/ui/browser_window_state.h" |
| 41 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 43 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
| 42 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 44 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 43 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 45 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
| 44 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 46 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 45 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 47 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 46 #import "chrome/browser/ui/cocoa/browser_window_layout.h" | 48 #import "chrome/browser/ui/cocoa/browser_window_layout.h" |
| 47 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 49 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 #include "components/translate/core/browser/translate_manager.h" | 90 #include "components/translate/core/browser/translate_manager.h" |
| 89 #include "components/translate/core/browser/translate_ui_delegate.h" | 91 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 90 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 92 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 91 #include "content/public/browser/render_view_host.h" | 93 #include "content/public/browser/render_view_host.h" |
| 92 #include "content/public/browser/render_widget_host_view.h" | 94 #include "content/public/browser/render_widget_host_view.h" |
| 93 #include "content/public/browser/web_contents.h" | 95 #include "content/public/browser/web_contents.h" |
| 94 #import "ui/base/cocoa/cocoa_base_utils.h" | 96 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 95 #import "ui/base/cocoa/nsview_additions.h" | 97 #import "ui/base/cocoa/nsview_additions.h" |
| 96 #include "ui/base/l10n/l10n_util.h" | 98 #include "ui/base/l10n/l10n_util.h" |
| 97 #include "ui/base/l10n/l10n_util_mac.h" | 99 #include "ui/base/l10n/l10n_util_mac.h" |
| 100 #import "ui/gfx/mac/coordinate_conversion.h" | |
| 98 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" | 101 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" |
| 99 | 102 |
| 100 using bookmarks::BookmarkModel; | 103 using bookmarks::BookmarkModel; |
| 101 using bookmarks::BookmarkNode; | 104 using bookmarks::BookmarkNode; |
| 102 using l10n_util::GetStringUTF16; | 105 using l10n_util::GetStringUTF16; |
| 103 using l10n_util::GetNSStringWithFixup; | 106 using l10n_util::GetNSStringWithFixup; |
| 104 using l10n_util::GetNSStringFWithFixup; | 107 using l10n_util::GetNSStringFWithFixup; |
| 105 | 108 |
| 106 // ORGANIZATION: This is a big file. It is (in principle) organized as follows | 109 // ORGANIZATION: This is a big file. It is (in principle) organized as follows |
| 107 // (in order): | 110 // (in order): |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // set a flag, and constrain any resize by the allowed amounts. On further | 178 // set a flag, and constrain any resize by the allowed amounts. On further |
| 176 // shrinks, we check the flag (since the size/position of the window will no | 179 // shrinks, we check the flag (since the size/position of the window will no |
| 177 // longer indicate that the window is shrinking from an apparent zoomed state) | 180 // longer indicate that the window is shrinking from an apparent zoomed state) |
| 178 // and if it's set we continue to constrain the resize. | 181 // and if it's set we continue to constrain the resize. |
| 179 | 182 |
| 180 using content::OpenURLParams; | 183 using content::OpenURLParams; |
| 181 using content::Referrer; | 184 using content::Referrer; |
| 182 using content::RenderWidgetHostView; | 185 using content::RenderWidgetHostView; |
| 183 using content::WebContents; | 186 using content::WebContents; |
| 184 | 187 |
| 188 @interface BrowserWindowController () | |
| 189 // Declared for ViewsBookmarkBubbleObserver. | |
| 190 - (void)viewsBookmarkBubbleClosed; | |
| 191 @end | |
| 192 | |
| 193 namespace { | |
| 194 | |
| 195 // Manages toolbar visibility locking and bookmark button pulsing. | |
| 196 class ViewsBookmarkBubbleObserver : public bookmarks::BookmarkBubbleObserver { | |
|
tapted
2015/08/21 07:19:18
This doesn't feel right in this file, but I haven'
jackhou1
2015/08/24 08:22:04
I decided to pull all the non-Views parts out to a
| |
| 197 public: | |
| 198 explicit ViewsBookmarkBubbleObserver(BrowserWindowController* controller) | |
| 199 : controller_(controller), lockOwner_([[NSObject alloc] init]) {} | |
| 200 ~ViewsBookmarkBubbleObserver() override {} | |
| 201 | |
| 202 // bookmarks::BookmarkBubbleObserver. | |
| 203 void OnBookmarkBubbleShown(const BookmarkNode* node) override { | |
| 204 [controller_ lockBarVisibilityForOwner:lockOwner_ | |
| 205 withAnimation:NO | |
| 206 delay:NO]; | |
| 207 pulsingBookmarkNode_ = | |
| 208 [[controller_ bookmarkBarController] startPulsingBookmarkNode:node]; | |
| 209 } | |
| 210 | |
| 211 void OnBookmarkBubbleHidden() override { | |
| 212 [controller_ releaseBarVisibilityForOwner:lockOwner_ | |
| 213 withAnimation:YES | |
| 214 delay:NO]; | |
| 215 [[controller_ bookmarkBarController] | |
| 216 stopPulsingBookmarkNode:pulsingBookmarkNode_]; | |
| 217 pulsingBookmarkNode_ = nullptr; | |
| 218 [controller_ viewsBookmarkBubbleClosed]; | |
| 219 } | |
| 220 | |
| 221 private: | |
| 222 BrowserWindowController* controller_; // Weak, owns us. | |
| 223 const BookmarkNode* pulsingBookmarkNode_ = nullptr; | |
| 224 base::scoped_nsobject<NSObject> lockOwner_; | |
| 225 | |
| 226 DISALLOW_COPY_AND_ASSIGN(ViewsBookmarkBubbleObserver); | |
| 227 }; | |
| 228 | |
| 229 } // namespace | |
| 230 | |
| 185 @interface NSWindow (NSPrivateApis) | 231 @interface NSWindow (NSPrivateApis) |
| 186 // Note: These functions are private, use -[NSObject respondsToSelector:] | 232 // Note: These functions are private, use -[NSObject respondsToSelector:] |
| 187 // before calling them. | 233 // before calling them. |
| 188 | 234 |
| 189 - (void)setBottomCornerRounded:(BOOL)rounded; | 235 - (void)setBottomCornerRounded:(BOOL)rounded; |
| 190 | 236 |
| 191 - (NSRect)_growBoxRect; | 237 - (NSRect)_growBoxRect; |
| 192 | 238 |
| 193 @end | 239 @end |
| 194 | 240 |
| (...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 alignment:alignment]; | 1805 alignment:alignment]; |
| 1760 } | 1806 } |
| 1761 | 1807 |
| 1762 - (NSPoint)bookmarkBubblePoint { | 1808 - (NSPoint)bookmarkBubblePoint { |
| 1763 return [toolbarController_ bookmarkBubblePoint]; | 1809 return [toolbarController_ bookmarkBubblePoint]; |
| 1764 } | 1810 } |
| 1765 | 1811 |
| 1766 // Show the bookmark bubble (e.g. user just clicked on the STAR). | 1812 // Show the bookmark bubble (e.g. user just clicked on the STAR). |
| 1767 - (void)showBookmarkBubbleForURL:(const GURL&)url | 1813 - (void)showBookmarkBubbleForURL:(const GURL&)url |
| 1768 alreadyBookmarked:(BOOL)alreadyMarked { | 1814 alreadyBookmarked:(BOOL)alreadyMarked { |
| 1815 if (chrome::ToolkitViewsDialogsEnabled()) { | |
| 1816 if (viewsBookmarkBubbleObserver_.get()) | |
| 1817 return; | |
| 1818 | |
| 1819 viewsBookmarkBubbleObserver_.reset(new ViewsBookmarkBubbleObserver(self)); | |
| 1820 chrome::ShowBookmarkBubbleViewsAtPoint( | |
| 1821 gfx::ScreenPointFromNSPoint( | |
| 1822 [[self window] convertBaseToScreen:[self bookmarkBubblePoint]]), | |
| 1823 [[self window] contentView], viewsBookmarkBubbleObserver_.get(), | |
| 1824 browser_.get(), url, alreadyMarked); | |
| 1825 return; | |
|
tapted
2015/08/21 07:19:18
DCHECK(viewsBookmarkBubbleObserver_) ?
jackhou1
2015/08/24 08:22:04
Done. Is this to ensure it's not closed immediatel
tapted
2015/08/25 03:10:16
oops - missed a question. I guess that's part of i
| |
| 1826 } | |
| 1827 | |
| 1769 if (!bookmarkBubbleController_) { | 1828 if (!bookmarkBubbleController_) { |
| 1770 BookmarkModel* model = | 1829 BookmarkModel* model = |
| 1771 BookmarkModelFactory::GetForProfile(browser_->profile()); | 1830 BookmarkModelFactory::GetForProfile(browser_->profile()); |
| 1772 bookmarks::ManagedBookmarkService* managed = | 1831 bookmarks::ManagedBookmarkService* managed = |
| 1773 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); | 1832 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); |
| 1774 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); | 1833 const BookmarkNode* node = model->GetMostRecentlyAddedUserNodeForURL(url); |
| 1775 bookmarkBubbleController_ = | 1834 bookmarkBubbleController_ = |
| 1776 [[BookmarkBubbleController alloc] initWithParentWindow:[self window] | 1835 [[BookmarkBubbleController alloc] initWithParentWindow:[self window] |
| 1777 managed:managed | 1836 managed:managed |
| 1778 model:model | 1837 model:model |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1791 - (void)bookmarkBubbleWindowWillClose:(NSNotification*)notification { | 1850 - (void)bookmarkBubbleWindowWillClose:(NSNotification*)notification { |
| 1792 DCHECK_EQ([notification object], [bookmarkBubbleController_ window]); | 1851 DCHECK_EQ([notification object], [bookmarkBubbleController_ window]); |
| 1793 | 1852 |
| 1794 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 1853 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 1795 [center removeObserver:self | 1854 [center removeObserver:self |
| 1796 name:NSWindowWillCloseNotification | 1855 name:NSWindowWillCloseNotification |
| 1797 object:[bookmarkBubbleController_ window]]; | 1856 object:[bookmarkBubbleController_ window]]; |
| 1798 bookmarkBubbleController_ = nil; | 1857 bookmarkBubbleController_ = nil; |
| 1799 } | 1858 } |
| 1800 | 1859 |
| 1860 - (void)viewsBookmarkBubbleClosed { | |
| 1861 viewsBookmarkBubbleObserver_.reset(); | |
| 1862 } | |
| 1863 | |
| 1801 // Handle the editBookmarkNode: action sent from bookmark bubble controllers. | 1864 // Handle the editBookmarkNode: action sent from bookmark bubble controllers. |
| 1802 - (void)editBookmarkNode:(id)sender { | 1865 - (void)editBookmarkNode:(id)sender { |
| 1803 BOOL responds = [sender respondsToSelector:@selector(node)]; | 1866 BOOL responds = [sender respondsToSelector:@selector(node)]; |
| 1804 DCHECK(responds); | 1867 DCHECK(responds); |
| 1805 if (responds) { | 1868 if (responds) { |
| 1806 const BookmarkNode* node = [sender node]; | 1869 const BookmarkNode* node = [sender node]; |
| 1807 if (node) | 1870 if (node) |
| 1808 BookmarkEditor::Show([self window], browser_->profile(), | 1871 BookmarkEditor::Show([self window], browser_->profile(), |
| 1809 BookmarkEditor::EditDetails::EditNode(node), | 1872 BookmarkEditor::EditDetails::EditNode(node), |
| 1810 BookmarkEditor::SHOW_TREE); | 1873 BookmarkEditor::SHOW_TREE); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2267 | 2330 |
| 2268 - (BOOL)supportsBookmarkBar { | 2331 - (BOOL)supportsBookmarkBar { |
| 2269 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2332 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2270 } | 2333 } |
| 2271 | 2334 |
| 2272 - (BOOL)isTabbedWindow { | 2335 - (BOOL)isTabbedWindow { |
| 2273 return browser_->is_type_tabbed(); | 2336 return browser_->is_type_tabbed(); |
| 2274 } | 2337 } |
| 2275 | 2338 |
| 2276 @end // @implementation BrowserWindowController(WindowType) | 2339 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |