OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/first_run_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/first_run/first_run.h" | 9 #include "chrome/browser/first_run/first_run.h" |
10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 10 #include "chrome/browser/search_engines/template_url_service_factory.h" |
11 #include "chrome/browser/ui/chrome_pages.h" | 11 #include "chrome/browser/ui/chrome_pages.h" |
12 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 12 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
13 #import "chrome/browser/ui/cocoa/l10n_util.h" | 13 #import "chrome/browser/ui/cocoa/l10n_util.h" |
14 #include "components/search_engines/util.h" | 14 #include "components/search_engines/util.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 | 16 |
| 17 @interface FirstRunKeyResponder : NSResponder |
| 18 @end |
| 19 |
| 20 @implementation FirstRunKeyResponder |
| 21 |
| 22 - (void)keyDown:(NSEvent*)event { |
| 23 // Pass the key event along to the browser window's first responder (which is |
| 24 // the omnibox). |
| 25 NSWindow* firstRunBubbleWindow = [event window]; |
| 26 [[[firstRunBubbleWindow parentWindow] firstResponder] keyDown:event]; |
| 27 |
| 28 // Remove the first run bubble from the screen and clean up. |
| 29 [firstRunBubbleWindow orderOut:nil]; |
| 30 [[firstRunBubbleWindow windowController] close]; |
| 31 } |
| 32 |
| 33 @end |
| 34 |
17 @interface FirstRunBubbleController(Private) | 35 @interface FirstRunBubbleController(Private) |
18 - (id)initRelativeToView:(NSView*)view | 36 - (id)initRelativeToView:(NSView*)view |
19 offset:(NSPoint)offset | 37 offset:(NSPoint)offset |
20 browser:(Browser*)browser | 38 browser:(Browser*)browser |
21 profile:(Profile*)profile; | 39 profile:(Profile*)profile; |
22 - (void)closeIfNotKey; | 40 - (void)closeIfNotKey; |
23 @end | 41 @end |
24 | 42 |
25 @implementation FirstRunBubbleController | 43 @implementation FirstRunBubbleController |
26 | 44 |
(...skipping 10 matching lines...) Expand all Loading... |
37 | 55 |
38 - (id)initRelativeToView:(NSView*)view | 56 - (id)initRelativeToView:(NSView*)view |
39 offset:(NSPoint)offset | 57 offset:(NSPoint)offset |
40 browser:(Browser*)browser | 58 browser:(Browser*)browser |
41 profile:(Profile*)profile { | 59 profile:(Profile*)profile { |
42 if ((self = [super initWithWindowNibPath:@"FirstRunBubble" | 60 if ((self = [super initWithWindowNibPath:@"FirstRunBubble" |
43 relativeToView:view | 61 relativeToView:view |
44 offset:offset])) { | 62 offset:offset])) { |
45 browser_ = browser; | 63 browser_ = browser; |
46 profile_ = profile; | 64 profile_ = profile; |
| 65 |
| 66 // Add a responder object to catch any key events that are not consumed |
| 67 // by controls in the bubble, so that user typing dismisses the bubble. |
| 68 keyResponder_.reset([[FirstRunKeyResponder alloc] init]); |
| 69 [[self window] setNextResponder:keyResponder_]; |
| 70 |
47 [self showWindow:nil]; | 71 [self showWindow:nil]; |
48 | 72 |
49 // On 10.5, the first run bubble sometimes does not disappear when clicking | 73 // On 10.5, the first run bubble sometimes does not disappear when clicking |
50 // the omnibox. This happens if the bubble never became key, due to it | 74 // the omnibox. This happens if the bubble never became key, due to it |
51 // showing up so early in the startup sequence. As a workaround, close it | 75 // showing up so early in the startup sequence. As a workaround, close it |
52 // automatically after a few seconds if it doesn't become key. | 76 // automatically after a few seconds if it doesn't become key. |
53 // http://crbug.com/52726 | 77 // http://crbug.com/52726 |
54 [self performSelector:@selector(closeIfNotKey) withObject:nil afterDelay:3]; | 78 [self performSelector:@selector(closeIfNotKey) withObject:nil afterDelay:3]; |
55 } | 79 } |
56 return self; | 80 return self; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 - (IBAction)onChange:(id)sender { | 117 - (IBAction)onChange:(id)sender { |
94 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); | 118 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); |
95 | 119 |
96 Browser* browser = browser_; | 120 Browser* browser = browser_; |
97 [self close]; | 121 [self close]; |
98 if (browser) | 122 if (browser) |
99 chrome::ShowSearchEngineSettings(browser); | 123 chrome::ShowSearchEngineSettings(browser); |
100 } | 124 } |
101 | 125 |
102 @end // FirstRunBubbleController | 126 @end // FirstRunBubbleController |
OLD | NEW |