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" |
| 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/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_command_controller.h" | 33 #include "chrome/browser/ui/browser_command_controller.h" |
| 33 #include "chrome/browser/ui/browser_commands.h" | 34 #include "chrome/browser/ui/browser_commands.h" |
| 34 #include "chrome/browser/ui/browser_instant_controller.h" | 35 #include "chrome/browser/ui/browser_instant_controller.h" |
| 35 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
| 36 #include "chrome/browser/ui/browser_window_state.h" | 37 #include "chrome/browser/ui/browser_window_state.h" |
| 37 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 38 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
| 38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 39 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 39 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 40 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 56 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 57 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 57 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 58 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 58 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" | 59 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 59 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" | 60 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" |
| 60 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | 61 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" |
| 61 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 62 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 62 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 63 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 63 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 64 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 64 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 65 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 65 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 66 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 67 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" | |
| 66 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 68 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 67 #include "chrome/browser/ui/omnibox/location_bar.h" | 69 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 68 #include "chrome/browser/ui/tabs/dock_info.h" | 70 #include "chrome/browser/ui/tabs/dock_info.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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1236 } | 1239 } |
| 1237 | 1240 |
| 1238 - (void)updateToolbarWithContents:(WebContents*)tab { | 1241 - (void)updateToolbarWithContents:(WebContents*)tab { |
| 1239 [toolbarController_ updateToolbarWithContents:tab]; | 1242 [toolbarController_ updateToolbarWithContents:tab]; |
| 1240 } | 1243 } |
| 1241 | 1244 |
| 1242 - (void)setStarredState:(BOOL)isStarred { | 1245 - (void)setStarredState:(BOOL)isStarred { |
| 1243 [toolbarController_ setStarredState:isStarred]; | 1246 [toolbarController_ setStarredState:isStarred]; |
| 1244 } | 1247 } |
| 1245 | 1248 |
| 1249 - (void)setCurrentPageIsTranslated:(BOOL)on { | |
| 1250 [toolbarController_ setTranslateIconLit:on]; | |
| 1251 } | |
| 1252 | |
| 1246 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { | 1253 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { |
| 1247 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; | 1254 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; |
| 1248 } | 1255 } |
| 1249 | 1256 |
| 1250 // Return the rect, in WebKit coordinates (flipped), of the window's grow box | 1257 // Return the rect, in WebKit coordinates (flipped), of the window's grow box |
| 1251 // in the coordinate system of the content area of the currently selected tab. | 1258 // in the coordinate system of the content area of the currently selected tab. |
| 1252 // |windowGrowBox| needs to be in the window's coordinate system. | 1259 // |windowGrowBox| needs to be in the window's coordinate system. |
| 1253 - (NSRect)selectedTabGrowBoxRect { | 1260 - (NSRect)selectedTabGrowBoxRect { |
| 1254 NSWindow* window = [self window]; | 1261 NSWindow* window = [self window]; |
| 1255 if (![window respondsToSelector:@selector(_growBoxRect)]) | 1262 if (![window respondsToSelector:@selector(_growBoxRect)]) |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1692 DCHECK(responds); | 1699 DCHECK(responds); |
| 1693 if (responds) { | 1700 if (responds) { |
| 1694 const BookmarkNode* node = [sender node]; | 1701 const BookmarkNode* node = [sender node]; |
| 1695 if (node) | 1702 if (node) |
| 1696 BookmarkEditor::Show([self window], browser_->profile(), | 1703 BookmarkEditor::Show([self window], browser_->profile(), |
| 1697 BookmarkEditor::EditDetails::EditNode(node), | 1704 BookmarkEditor::EditDetails::EditNode(node), |
| 1698 BookmarkEditor::SHOW_TREE); | 1705 BookmarkEditor::SHOW_TREE); |
| 1699 } | 1706 } |
| 1700 } | 1707 } |
| 1701 | 1708 |
| 1709 - (void)showTranslateBubbleForWebContents:(content::WebContents*)contents | |
| 1710 step: | |
| 1711 (TranslateTabHelper::TranslateStep)step | |
| 1712 errorType:(TranslateErrors::Type)errorType { | |
| 1713 // fixme(hajimehoshi): The similar logic exists at TranslateBubbleView:: | |
|
Robert Sesek
2014/02/27 20:45:01
TODO not fixme
hajimehoshi
2014/02/28 04:25:22
Done.
| |
| 1714 // ShowBubble. This should be unified. | |
| 1715 if (translateBubbleController_) { | |
| 1716 // When the user reads the advanced setting panel, the bubble should not be | |
| 1717 // changed because he/she is focusing on the bubble. | |
| 1718 if (translateBubbleController_.webContents == contents && | |
| 1719 translateBubbleController_.model->GetViewState() == | |
| 1720 TranslateBubbleModel::VIEW_STATE_ADVANCED) { | |
| 1721 return; | |
| 1722 } | |
| 1723 if (step != TranslateTabHelper::TRANSLATE_ERROR) { | |
| 1724 TranslateBubbleModel::ViewState viewState = | |
| 1725 TranslateBubbleModelImpl::TranslateStepToViewState(step); | |
| 1726 [translateBubbleController_ switchView:viewState]; | |
| 1727 } else { | |
| 1728 [translateBubbleController_ switchToErrorView:errorType]; | |
| 1729 } | |
| 1730 return; | |
| 1731 } | |
| 1732 | |
| 1733 // fixme(hajimehoshi): Set the initial languages correctly. | |
|
Robert Sesek
2014/02/27 20:45:01
TODO
hajimehoshi
2014/02/28 04:25:22
Done.
| |
| 1734 std::string sourceLanguage = "xx"; | |
| 1735 std::string targetLanguage = "yy"; | |
| 1736 | |
| 1737 scoped_ptr<TranslateUIDelegate> uiDelegate( | |
| 1738 new TranslateUIDelegate(contents, sourceLanguage, targetLanguage)); | |
| 1739 scoped_ptr<TranslateBubbleModel> model( | |
| 1740 new TranslateBubbleModelImpl(step, uiDelegate.Pass())); | |
| 1741 translateBubbleController_ = [[TranslateBubbleController alloc] | |
| 1742 initWithParentWindow:self | |
| 1743 model:model.Pass() | |
| 1744 webContents:contents]; | |
| 1745 [translateBubbleController_ showWindow:nil]; | |
| 1746 | |
| 1747 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | |
| 1748 [center addObserver:self | |
| 1749 selector:@selector(translateBubbleWindowWillClose:) | |
| 1750 name:NSWindowWillCloseNotification | |
| 1751 object:[translateBubbleController_ window]]; | |
| 1752 } | |
| 1753 | |
| 1754 // Nil out the weak translate bubble controller reference. | |
| 1755 - (void)translateBubbleWindowWillClose:(NSNotification*)notification { | |
| 1756 DCHECK_EQ([notification object], [translateBubbleController_ window]); | |
| 1757 | |
| 1758 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | |
| 1759 [center removeObserver:self | |
| 1760 name:NSWindowWillCloseNotification | |
| 1761 object:[translateBubbleController_ window]]; | |
| 1762 translateBubbleController_ = nil; | |
| 1763 } | |
| 1764 | |
| 1702 // If the browser is in incognito mode or has multi-profiles, install the image | 1765 // If the browser is in incognito mode or has multi-profiles, install the image |
| 1703 // view to decorate the window at the upper right. Use the same base y | 1766 // view to decorate the window at the upper right. Use the same base y |
| 1704 // coordinate as the tab strip. | 1767 // coordinate as the tab strip. |
| 1705 - (void)installAvatar { | 1768 - (void)installAvatar { |
| 1706 // Install the image into the badge view. Hide it for now; positioning and | 1769 // Install the image into the badge view. Hide it for now; positioning and |
| 1707 // sizing will be done by the layout code. The AvatarIcon will choose which | 1770 // sizing will be done by the layout code. The AvatarIcon will choose which |
| 1708 // image to display based on the browser. The AvatarButton will display | 1771 // image to display based on the browser. The AvatarButton will display |
| 1709 // the browser profile's name unless the browser is incognito. | 1772 // the browser profile's name unless the browser is incognito. |
| 1710 NSView* view; | 1773 NSView* view; |
| 1711 if ([self shouldUseNewAvatarButton]) { | 1774 if ([self shouldUseNewAvatarButton]) { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2189 | 2252 |
| 2190 - (BOOL)supportsBookmarkBar { | 2253 - (BOOL)supportsBookmarkBar { |
| 2191 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2254 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2192 } | 2255 } |
| 2193 | 2256 |
| 2194 - (BOOL)isTabbedWindow { | 2257 - (BOOL)isTabbedWindow { |
| 2195 return browser_->is_type_tabbed(); | 2258 return browser_->is_type_tabbed(); |
| 2196 } | 2259 } |
| 2197 | 2260 |
| 2198 @end // @implementation BrowserWindowController(WindowType) | 2261 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |