OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "chrome/browser/speech/speech_input_bubble.h" | 7 #include "chrome/browser/speech/speech_input_bubble.h" |
8 | 8 |
9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 12 matching lines...) Loading... |
23 Delegate* delegate, | 23 Delegate* delegate, |
24 const gfx::Rect& element_rect); | 24 const gfx::Rect& element_rect); |
25 virtual ~SpeechInputBubbleImpl(); | 25 virtual ~SpeechInputBubbleImpl(); |
26 virtual void Show(); | 26 virtual void Show(); |
27 virtual void Hide(); | 27 virtual void Hide(); |
28 virtual void UpdateLayout(); | 28 virtual void UpdateLayout(); |
29 virtual void SetImage(const SkBitmap& image); | 29 virtual void SetImage(const SkBitmap& image); |
30 | 30 |
31 private: | 31 private: |
32 scoped_nsobject<SpeechInputWindowController> window_; | 32 scoped_nsobject<SpeechInputWindowController> window_; |
33 TabContents* tab_contents_; | |
34 Delegate* delegate_; | 33 Delegate* delegate_; |
35 gfx::Rect element_rect_; | 34 gfx::Rect element_rect_; |
36 }; | 35 }; |
37 | 36 |
38 SpeechInputBubbleImpl::SpeechInputBubbleImpl(TabContents* tab_contents, | 37 SpeechInputBubbleImpl::SpeechInputBubbleImpl(TabContents* tab_contents, |
39 Delegate* delegate, | 38 Delegate* delegate, |
40 const gfx::Rect& element_rect) | 39 const gfx::Rect& element_rect) |
41 : tab_contents_(tab_contents), | 40 : SpeechInputBubbleBase(tab_contents), |
42 delegate_(delegate), | 41 delegate_(delegate), |
43 element_rect_(element_rect) { | 42 element_rect_(element_rect) { |
44 } | 43 } |
45 | 44 |
46 SpeechInputBubbleImpl::~SpeechInputBubbleImpl() { | 45 SpeechInputBubbleImpl::~SpeechInputBubbleImpl() { |
47 if (window_.get()) | 46 if (window_.get()) |
48 [window_.get() close]; | 47 [window_.get() close]; |
49 } | 48 } |
50 | 49 |
51 void SpeechInputBubbleImpl::SetImage(const SkBitmap& image) { | 50 void SpeechInputBubbleImpl::SetImage(const SkBitmap& image) { |
52 if (window_.get()) | 51 if (window_.get()) |
53 [window_.get() setImage:gfx::SkBitmapToNSImage(image)]; | 52 [window_.get() setImage:gfx::SkBitmapToNSImage(image)]; |
54 } | 53 } |
55 | 54 |
56 void SpeechInputBubbleImpl::Show() { | 55 void SpeechInputBubbleImpl::Show() { |
57 if (window_.get()) { | 56 if (window_.get()) { |
58 [window_.get() show]; | 57 [window_.get() show]; |
59 return; | 58 return; |
60 } | 59 } |
61 | 60 |
62 // Find the screen coordinates for the given tab and position the bubble's | 61 // Find the screen coordinates for the given tab and position the bubble's |
63 // arrow anchor point inside that to point at the bottom-left of the html | 62 // arrow anchor point inside that to point at the bottom-left of the html |
64 // input element rect. | 63 // input element rect. |
65 gfx::NativeView view = tab_contents_->view()->GetNativeView(); | 64 gfx::NativeView view = tab_contents()->view()->GetNativeView(); |
66 NSRect tab_bounds = [view bounds]; | 65 NSRect tab_bounds = [view bounds]; |
67 NSPoint anchor = NSMakePoint( | 66 NSPoint anchor = NSMakePoint( |
68 tab_bounds.origin.x + element_rect_.x() + kBubbleTargetOffsetX, | 67 tab_bounds.origin.x + element_rect_.x() + kBubbleTargetOffsetX, |
69 tab_bounds.origin.y + tab_bounds.size.height - element_rect_.y() - | 68 tab_bounds.origin.y + tab_bounds.size.height - element_rect_.y() - |
70 element_rect_.height()); | 69 element_rect_.height()); |
71 anchor = [view convertPoint:anchor toView:nil]; | 70 anchor = [view convertPoint:anchor toView:nil]; |
72 anchor = [[view window] convertBaseToScreen:anchor]; | 71 anchor = [[view window] convertBaseToScreen:anchor]; |
73 | 72 |
74 window_.reset([[SpeechInputWindowController alloc] | 73 window_.reset([[SpeechInputWindowController alloc] |
75 initWithParentWindow:tab_contents_->view()->GetTopLevelNativeWindow() | 74 initWithParentWindow:tab_contents()->view()->GetTopLevelNativeWindow() |
76 delegate:delegate_ | 75 delegate:delegate_ |
77 anchoredAt:anchor]); | 76 anchoredAt:anchor]); |
78 | 77 |
79 UpdateLayout(); | 78 UpdateLayout(); |
80 } | 79 } |
81 | 80 |
82 void SpeechInputBubbleImpl::Hide() { | 81 void SpeechInputBubbleImpl::Hide() { |
83 if (!window_.get()) | 82 if (!window_.get()) |
84 return; | 83 return; |
85 | 84 |
(...skipping 11 matching lines...) Loading... |
97 | 96 |
98 } // namespace | 97 } // namespace |
99 | 98 |
100 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( | 99 SpeechInputBubble* SpeechInputBubble::CreateNativeBubble( |
101 TabContents* tab_contents, | 100 TabContents* tab_contents, |
102 Delegate* delegate, | 101 Delegate* delegate, |
103 const gfx::Rect& element_rect) { | 102 const gfx::Rect& element_rect) { |
104 return new SpeechInputBubbleImpl(tab_contents, delegate, element_rect); | 103 return new SpeechInputBubbleImpl(tab_contents, delegate, element_rect); |
105 } | 104 } |
106 | 105 |
OLD | NEW |