| 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" |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #import "base/mac/foundation_util.h" | 12 #import "base/mac/foundation_util.h" |
| 13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 14 #import "base/mac/sdk_forward_declarations.h" | 14 #import "base/mac/sdk_forward_declarations.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/app/chrome_command_ids.h" // IDC_* | 17 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/devtools/devtools_window.h" | 20 #include "chrome/browser/devtools/devtools_window.h" |
| 21 #include "chrome/browser/fullscreen.h" | 21 #include "chrome/browser/fullscreen.h" |
| 22 #include "chrome/browser/profiles/avatar_menu.h" | 22 #include "chrome/browser/profiles/avatar_menu.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_info_cache.h" | 24 #include "chrome/browser/profiles/profile_info_cache.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/profiles/profiles_state.h" | 26 #include "chrome/browser/profiles/profiles_state.h" |
| 27 #include "chrome/browser/signin/signin_ui_util.h" | 27 #include "chrome/browser/signin/signin_ui_util.h" |
| 28 #include "chrome/browser/themes/theme_service.h" | 28 #include "chrome/browser/themes/theme_service.h" |
| 29 #include "chrome/browser/themes/theme_service_factory.h" | 29 #include "chrome/browser/themes/theme_service_factory.h" |
| 30 #include "chrome/browser/translate/translate_ui_delegate.h" |
| 30 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 31 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
| 31 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 32 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 32 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_command_controller.h" | 34 #include "chrome/browser/ui/browser_command_controller.h" |
| 34 #include "chrome/browser/ui/browser_commands.h" | 35 #include "chrome/browser/ui/browser_commands.h" |
| 35 #include "chrome/browser/ui/browser_instant_controller.h" | 36 #include "chrome/browser/ui/browser_instant_controller.h" |
| 36 #include "chrome/browser/ui/browser_list.h" | 37 #include "chrome/browser/ui/browser_list.h" |
| 37 #include "chrome/browser/ui/browser_window_state.h" | 38 #include "chrome/browser/ui/browser_window_state.h" |
| 38 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 39 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
| 39 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 40 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 58 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 58 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 59 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 59 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 60 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 60 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" | 61 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 61 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 62 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
| 62 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 63 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 63 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 64 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 64 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 65 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 65 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 66 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 66 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 67 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 68 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" |
| 67 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 69 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 68 #include "chrome/browser/ui/omnibox/location_bar.h" | 70 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 69 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 71 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 70 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 72 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 71 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 73 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 74 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
| 72 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 75 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 73 #include "chrome/common/chrome_switches.h" | 76 #include "chrome/common/chrome_switches.h" |
| 74 #include "chrome/common/profile_management_switches.h" | 77 #include "chrome/common/profile_management_switches.h" |
| 75 #include "chrome/common/url_constants.h" | 78 #include "chrome/common/url_constants.h" |
| 76 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 79 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 77 #include "content/public/browser/render_view_host.h" | 80 #include "content/public/browser/render_view_host.h" |
| 78 #include "content/public/browser/render_widget_host_view.h" | 81 #include "content/public/browser/render_widget_host_view.h" |
| 79 #include "content/public/browser/web_contents.h" | 82 #include "content/public/browser/web_contents.h" |
| 80 #include "content/public/browser/web_contents_view.h" | 83 #include "content/public/browser/web_contents_view.h" |
| 81 #include "grit/chromium_strings.h" | 84 #include "grit/chromium_strings.h" |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 } | 1247 } |
| 1245 | 1248 |
| 1246 - (void)updateToolbarWithContents:(WebContents*)tab { | 1249 - (void)updateToolbarWithContents:(WebContents*)tab { |
| 1247 [toolbarController_ updateToolbarWithContents:tab]; | 1250 [toolbarController_ updateToolbarWithContents:tab]; |
| 1248 } | 1251 } |
| 1249 | 1252 |
| 1250 - (void)setStarredState:(BOOL)isStarred { | 1253 - (void)setStarredState:(BOOL)isStarred { |
| 1251 [toolbarController_ setStarredState:isStarred]; | 1254 [toolbarController_ setStarredState:isStarred]; |
| 1252 } | 1255 } |
| 1253 | 1256 |
| 1257 - (void)setCurrentPageIsTranslated:(BOOL)on { |
| 1258 [toolbarController_ setTranslateIconLit:on]; |
| 1259 } |
| 1260 |
| 1254 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { | 1261 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { |
| 1255 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; | 1262 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; |
| 1256 } | 1263 } |
| 1257 | 1264 |
| 1258 // Return the rect, in WebKit coordinates (flipped), of the window's grow box | 1265 // Return the rect, in WebKit coordinates (flipped), of the window's grow box |
| 1259 // in the coordinate system of the content area of the currently selected tab. | 1266 // in the coordinate system of the content area of the currently selected tab. |
| 1260 // |windowGrowBox| needs to be in the window's coordinate system. | 1267 // |windowGrowBox| needs to be in the window's coordinate system. |
| 1261 - (NSRect)selectedTabGrowBoxRect { | 1268 - (NSRect)selectedTabGrowBoxRect { |
| 1262 NSWindow* window = [self window]; | 1269 NSWindow* window = [self window]; |
| 1263 if (![window respondsToSelector:@selector(_growBoxRect)]) | 1270 if (![window respondsToSelector:@selector(_growBoxRect)]) |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 DCHECK(responds); | 1737 DCHECK(responds); |
| 1731 if (responds) { | 1738 if (responds) { |
| 1732 const BookmarkNode* node = [sender node]; | 1739 const BookmarkNode* node = [sender node]; |
| 1733 if (node) | 1740 if (node) |
| 1734 BookmarkEditor::Show([self window], browser_->profile(), | 1741 BookmarkEditor::Show([self window], browser_->profile(), |
| 1735 BookmarkEditor::EditDetails::EditNode(node), | 1742 BookmarkEditor::EditDetails::EditNode(node), |
| 1736 BookmarkEditor::SHOW_TREE); | 1743 BookmarkEditor::SHOW_TREE); |
| 1737 } | 1744 } |
| 1738 } | 1745 } |
| 1739 | 1746 |
| 1747 - (void)showTranslateBubbleForWebContents:(content::WebContents*)contents |
| 1748 step: |
| 1749 (TranslateTabHelper::TranslateStep)step |
| 1750 errorType:(TranslateErrors::Type)errorType { |
| 1751 // TODO(hajimehoshi): The similar logic exists at TranslateBubbleView:: |
| 1752 // ShowBubble. This should be unified. |
| 1753 if (translateBubbleController_) { |
| 1754 // When the user reads the advanced setting panel, the bubble should not be |
| 1755 // changed because he/she is focusing on the bubble. |
| 1756 if (translateBubbleController_.webContents == contents && |
| 1757 translateBubbleController_.model->GetViewState() == |
| 1758 TranslateBubbleModel::VIEW_STATE_ADVANCED) { |
| 1759 return; |
| 1760 } |
| 1761 if (step != TranslateTabHelper::TRANSLATE_ERROR) { |
| 1762 TranslateBubbleModel::ViewState viewState = |
| 1763 TranslateBubbleModelImpl::TranslateStepToViewState(step); |
| 1764 [translateBubbleController_ switchView:viewState]; |
| 1765 } else { |
| 1766 [translateBubbleController_ switchToErrorView:errorType]; |
| 1767 } |
| 1768 return; |
| 1769 } |
| 1770 |
| 1771 // TODO(hajimehoshi): Set the initial languages correctly. |
| 1772 std::string sourceLanguage = "xx"; |
| 1773 std::string targetLanguage = "yy"; |
| 1774 |
| 1775 scoped_ptr<TranslateUIDelegate> uiDelegate( |
| 1776 new TranslateUIDelegate(contents, sourceLanguage, targetLanguage)); |
| 1777 scoped_ptr<TranslateBubbleModel> model( |
| 1778 new TranslateBubbleModelImpl(step, uiDelegate.Pass())); |
| 1779 translateBubbleController_ = [[TranslateBubbleController alloc] |
| 1780 initWithParentWindow:self |
| 1781 model:model.Pass() |
| 1782 webContents:contents]; |
| 1783 [translateBubbleController_ showWindow:nil]; |
| 1784 |
| 1785 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 1786 [center addObserver:self |
| 1787 selector:@selector(translateBubbleWindowWillClose:) |
| 1788 name:NSWindowWillCloseNotification |
| 1789 object:[translateBubbleController_ window]]; |
| 1790 } |
| 1791 |
| 1792 // Nil out the weak translate bubble controller reference. |
| 1793 - (void)translateBubbleWindowWillClose:(NSNotification*)notification { |
| 1794 DCHECK_EQ([notification object], [translateBubbleController_ window]); |
| 1795 |
| 1796 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 1797 [center removeObserver:self |
| 1798 name:NSWindowWillCloseNotification |
| 1799 object:[translateBubbleController_ window]]; |
| 1800 translateBubbleController_ = nil; |
| 1801 } |
| 1802 |
| 1740 // If the browser is in incognito mode or has multi-profiles, install the image | 1803 // If the browser is in incognito mode or has multi-profiles, install the image |
| 1741 // view to decorate the window at the upper right. Use the same base y | 1804 // view to decorate the window at the upper right. Use the same base y |
| 1742 // coordinate as the tab strip. | 1805 // coordinate as the tab strip. |
| 1743 - (void)installAvatar { | 1806 - (void)installAvatar { |
| 1744 // Install the image into the badge view. Hide it for now; positioning and | 1807 // Install the image into the badge view. Hide it for now; positioning and |
| 1745 // sizing will be done by the layout code. The AvatarIcon will choose which | 1808 // sizing will be done by the layout code. The AvatarIcon will choose which |
| 1746 // image to display based on the browser. The AvatarButton will display | 1809 // image to display based on the browser. The AvatarButton will display |
| 1747 // the browser profile's name unless the browser is incognito. | 1810 // the browser profile's name unless the browser is incognito. |
| 1748 NSView* view; | 1811 NSView* view; |
| 1749 if ([self shouldUseNewAvatarButton]) { | 1812 if ([self shouldUseNewAvatarButton]) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 | 2298 |
| 2236 - (BOOL)supportsBookmarkBar { | 2299 - (BOOL)supportsBookmarkBar { |
| 2237 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2300 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2238 } | 2301 } |
| 2239 | 2302 |
| 2240 - (BOOL)isTabbedWindow { | 2303 - (BOOL)isTabbedWindow { |
| 2241 return browser_->is_type_tabbed(); | 2304 return browser_->is_type_tabbed(); |
| 2242 } | 2305 } |
| 2243 | 2306 |
| 2244 @end // @implementation BrowserWindowController(WindowType) | 2307 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |