Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 151283006: Mac OS X: Show the Translate icon on Omnibox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue-307352-translate-bubble-2
Patch Set: Use kAnimateNone Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/cocoa/website_settings/permission_bubble_cocoa.h" 69 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
68 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 70 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
69 #include "chrome/browser/ui/omnibox/location_bar.h" 71 #include "chrome/browser/ui/omnibox/location_bar.h"
70 #include "chrome/browser/ui/tabs/tab_strip_model.h" 72 #include "chrome/browser/ui/tabs/tab_strip_model.h"
71 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" 73 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
72 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" 74 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
75 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
73 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 76 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
74 #include "chrome/browser/ui/window_sizer/window_sizer.h" 77 #include "chrome/browser/ui/window_sizer/window_sizer.h"
75 #include "chrome/common/chrome_switches.h" 78 #include "chrome/common/chrome_switches.h"
76 #include "chrome/common/extensions/command.h" 79 #include "chrome/common/extensions/command.h"
77 #include "chrome/common/profile_management_switches.h" 80 #include "chrome/common/profile_management_switches.h"
78 #include "chrome/common/url_constants.h" 81 #include "chrome/common/url_constants.h"
79 #include "components/web_modal/web_contents_modal_dialog_manager.h" 82 #include "components/web_modal/web_contents_modal_dialog_manager.h"
80 #include "content/public/browser/render_view_host.h" 83 #include "content/public/browser/render_view_host.h"
81 #include "content/public/browser/render_widget_host_view.h" 84 #include "content/public/browser/render_widget_host_view.h"
82 #include "content/public/browser/web_contents.h" 85 #include "content/public/browser/web_contents.h"
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 } 1257 }
1255 1258
1256 - (void)updateToolbarWithContents:(WebContents*)tab { 1259 - (void)updateToolbarWithContents:(WebContents*)tab {
1257 [toolbarController_ updateToolbarWithContents:tab]; 1260 [toolbarController_ updateToolbarWithContents:tab];
1258 } 1261 }
1259 1262
1260 - (void)setStarredState:(BOOL)isStarred { 1263 - (void)setStarredState:(BOOL)isStarred {
1261 [toolbarController_ setStarredState:isStarred]; 1264 [toolbarController_ setStarredState:isStarred];
1262 } 1265 }
1263 1266
1267 - (void)setCurrentPageIsTranslated:(BOOL)on {
1268 [toolbarController_ setTranslateIconLit:on];
1269 }
1270
1264 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { 1271 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble {
1265 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; 1272 [toolbarController_ zoomChangedForActiveTab:canShowBubble];
1266 } 1273 }
1267 1274
1268 // Return the rect, in WebKit coordinates (flipped), of the window's grow box 1275 // Return the rect, in WebKit coordinates (flipped), of the window's grow box
1269 // in the coordinate system of the content area of the currently selected tab. 1276 // in the coordinate system of the content area of the currently selected tab.
1270 // |windowGrowBox| needs to be in the window's coordinate system. 1277 // |windowGrowBox| needs to be in the window's coordinate system.
1271 - (NSRect)selectedTabGrowBoxRect { 1278 - (NSRect)selectedTabGrowBoxRect {
1272 NSWindow* window = [self window]; 1279 NSWindow* window = [self window];
1273 if (![window respondsToSelector:@selector(_growBoxRect)]) 1280 if (![window respondsToSelector:@selector(_growBoxRect)])
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 DCHECK(responds); 1755 DCHECK(responds);
1749 if (responds) { 1756 if (responds) {
1750 const BookmarkNode* node = [sender node]; 1757 const BookmarkNode* node = [sender node];
1751 if (node) 1758 if (node)
1752 BookmarkEditor::Show([self window], browser_->profile(), 1759 BookmarkEditor::Show([self window], browser_->profile(),
1753 BookmarkEditor::EditDetails::EditNode(node), 1760 BookmarkEditor::EditDetails::EditNode(node),
1754 BookmarkEditor::SHOW_TREE); 1761 BookmarkEditor::SHOW_TREE);
1755 } 1762 }
1756 } 1763 }
1757 1764
1765 - (void)showTranslateBubbleForWebContents:(content::WebContents*)contents
1766 step:
1767 (TranslateTabHelper::TranslateStep)step
1768 errorType:(TranslateErrors::Type)errorType {
1769 // TODO(hajimehoshi): The similar logic exists at TranslateBubbleView::
1770 // ShowBubble. This should be unified.
1771 if (translateBubbleController_) {
1772 // When the user reads the advanced setting panel, the bubble should not be
1773 // changed because he/she is focusing on the bubble.
1774 if (translateBubbleController_.webContents == contents &&
1775 translateBubbleController_.model->GetViewState() ==
1776 TranslateBubbleModel::VIEW_STATE_ADVANCED) {
1777 return;
1778 }
1779 if (step != TranslateTabHelper::TRANSLATE_ERROR) {
1780 TranslateBubbleModel::ViewState viewState =
1781 TranslateBubbleModelImpl::TranslateStepToViewState(step);
1782 [translateBubbleController_ switchView:viewState];
1783 } else {
1784 [translateBubbleController_ switchToErrorView:errorType];
1785 }
1786 return;
1787 }
1788
1789 // TODO(hajimehoshi): Set the initial languages correctly.
1790 std::string sourceLanguage = "xx";
1791 std::string targetLanguage = "yy";
1792
1793 scoped_ptr<TranslateUIDelegate> uiDelegate(
1794 new TranslateUIDelegate(contents, sourceLanguage, targetLanguage));
1795 scoped_ptr<TranslateBubbleModel> model(
1796 new TranslateBubbleModelImpl(step, uiDelegate.Pass()));
1797 translateBubbleController_ = [[TranslateBubbleController alloc]
1798 initWithParentWindow:self
1799 model:model.Pass()
1800 webContents:contents];
1801 [translateBubbleController_ showWindow:nil];
1802
1803 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
1804 [center addObserver:self
1805 selector:@selector(translateBubbleWindowWillClose:)
1806 name:NSWindowWillCloseNotification
1807 object:[translateBubbleController_ window]];
1808 }
1809
1810 // Nil out the weak translate bubble controller reference.
1811 - (void)translateBubbleWindowWillClose:(NSNotification*)notification {
1812 DCHECK_EQ([notification object], [translateBubbleController_ window]);
1813
1814 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
1815 [center removeObserver:self
1816 name:NSWindowWillCloseNotification
1817 object:[translateBubbleController_ window]];
1818 translateBubbleController_ = nil;
1819 }
1820
1758 // If the browser is in incognito mode or has multi-profiles, install the image 1821 // If the browser is in incognito mode or has multi-profiles, install the image
1759 // view to decorate the window at the upper right. Use the same base y 1822 // view to decorate the window at the upper right. Use the same base y
1760 // coordinate as the tab strip. 1823 // coordinate as the tab strip.
1761 - (void)installAvatar { 1824 - (void)installAvatar {
1762 // Install the image into the badge view. Hide it for now; positioning and 1825 // Install the image into the badge view. Hide it for now; positioning and
1763 // sizing will be done by the layout code. The AvatarIcon will choose which 1826 // sizing will be done by the layout code. The AvatarIcon will choose which
1764 // image to display based on the browser. The AvatarButton will display 1827 // image to display based on the browser. The AvatarButton will display
1765 // the browser profile's name unless the browser is incognito. 1828 // the browser profile's name unless the browser is incognito.
1766 NSView* view; 1829 NSView* view;
1767 if ([self shouldUseNewAvatarButton]) { 1830 if ([self shouldUseNewAvatarButton]) {
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 2325
2263 - (BOOL)supportsBookmarkBar { 2326 - (BOOL)supportsBookmarkBar {
2264 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2327 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2265 } 2328 }
2266 2329
2267 - (BOOL)isTabbedWindow { 2330 - (BOOL)isTabbedWindow {
2268 return browser_->is_type_tabbed(); 2331 return browser_->is_type_tabbed();
2269 } 2332 }
2270 2333
2271 @end // @implementation BrowserWindowController(WindowType) 2334 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698