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

Side by Side Diff: views/bubble/bubble_delegate.cc

Issue 8368006: Support Windows native textfield, combobox, etc. in new bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "views/bubble/bubble_delegate.h" 5 #include "views/bubble/bubble_delegate.h"
6 6
7 #include "ui/base/animation/slide_animation.h" 7 #include "ui/base/animation/slide_animation.h"
8 #include "views/bubble/bubble_frame_view.h" 8 #include "views/bubble/bubble_frame_view.h"
9 #include "views/widget/widget.h" 9 #include "views/widget/widget.h"
10 10
(...skipping 15 matching lines...) Expand all
26 BubbleBorder::ArrowLocation arrow_location, 26 BubbleBorder::ArrowLocation arrow_location,
27 const SkColor& color) 27 const SkColor& color)
28 : WidgetDelegateView(), 28 : WidgetDelegateView(),
29 close_on_esc_(true), 29 close_on_esc_(true),
30 anchor_point_(anchor_point), 30 anchor_point_(anchor_point),
31 arrow_location_(arrow_location), 31 arrow_location_(arrow_location),
32 color_(color) { 32 color_(color) {
33 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); 33 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
34 } 34 }
35 35
36 BubbleDelegateView::~BubbleDelegateView() {} 36 BubbleDelegateView::~BubbleDelegateView() {
37 border_widget_->Close();
38 }
37 39
38 // static 40 // static
39 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, 41 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate,
40 Widget* parent_widget) { 42 Widget* parent_widget) {
41 bubble_delegate->Init(); 43 bubble_delegate->Init();
42 views::Widget* bubble_widget = new views::Widget(); 44
43 views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE); 45 // Create a widget to host the border with transparency on.
44 params.delegate = bubble_delegate; 46 views::Widget* border_widget = new views::Widget();
45 params.transparent = true; 47 views::Widget::InitParams border_params(
48 views::Widget::InitParams::TYPE_BUBBLE);
49 border_params.delegate = new BubbleBorderDelegateView(bubble_delegate);
50 border_params.transparent = true;
46 if (!parent_widget) 51 if (!parent_widget)
47 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 52 border_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
48 params.parent_widget = parent_widget; 53 border_params.parent_widget = parent_widget;
49 bubble_widget->Init(params); 54 border_widget->Init(border_params);
50 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); 55 bubble_delegate->border_widget_ = border_widget;
51 return bubble_widget; 56
57 // Create a widget to host the content with transparency off.
Ben Goodger (Google) 2011/10/25 15:29:36 pull the border widget init into a separate functi
msw 2011/10/27 02:01:45 Done (sort of, let me know what you think).
58 views::Widget* content_widget = new views::Widget();
59 views::Widget::InitParams content_params(
60 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
61 content_params.delegate = bubble_delegate;
62 content_params.transparent = false;
63 content_params.parent_widget = border_widget;
64 content_widget->Init(content_params);
65 content_widget->SetContentsView(bubble_delegate);
66
67 border_widget->SetBounds(bubble_delegate->GetBubbleBounds());
68 gfx::Rect content_bounds = border_widget->GetClientAreaScreenBounds();
69 content_bounds.Inset(bubble_delegate->GetBubbleFrameView()->GetInsets());
70 // TODO(msw): Adjust bounds so contents can't obscure the rounded corners.
71 content_bounds.Inset(gfx::Insets(2, 2, 2, 2));
72 content_widget->SetBounds(content_bounds);
73
74 // TODO(msw): Fixup show/close/hide/opacity, etc.
75 content_widget->Show();
76 border_widget->Show();
77
78 // TODO(msw): Better transparency
79 HWND hwnd = content_widget->GetNativeView();
80 SetWindowLong(hwnd, GWL_EXSTYLE,
81 GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
82
83 // TODO(msw): Better content/border focus and z-ordering.
84 //border_widget->MoveAboveWidget(content_widget);
85 //content_widget->MoveAboveWidget(border_widget);
86 //if (parent_widget)
87 // parent_widget->MoveAboveWidget(border_widget);
88 //border_widget->MoveToTop();
89 //content_widget->MoveToTop();
90
91 return content_widget;
52 } 92 }
53 93
54 View* BubbleDelegateView::GetInitiallyFocusedView() { 94 View* BubbleDelegateView::GetInitiallyFocusedView() {
55 return this; 95 return this;
56 } 96 }
57 97
58 View* BubbleDelegateView::GetContentsView() { 98 View* BubbleDelegateView::GetContentsView() {
59 return this; 99 return this;
60 } 100 }
61 101
62 ClientView* BubbleDelegateView::CreateClientView(Widget* widget) { 102 ClientView* BubbleDelegateView::CreateClientView(Widget* widget) {
63 return new ClientView(widget, GetContentsView()); 103 return new ClientView(widget, GetContentsView());
64 } 104 }
65 105
66 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { 106 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() {
67 return new BubbleFrameView(GetArrowLocation(), 107 return NULL;
68 GetPreferredSize(),
69 GetColor());
70 } 108 }
71 109
72 gfx::Point BubbleDelegateView::GetAnchorPoint() const { 110 gfx::Point BubbleDelegateView::GetAnchorPoint() const {
73 return anchor_point_; 111 return anchor_point_;
74 } 112 }
75 113
76 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { 114 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const {
77 return arrow_location_; 115 return arrow_location_;
78 } 116 }
79 117
80 SkColor BubbleDelegateView::GetColor() const { 118 SkColor BubbleDelegateView::GetColor() const {
81 return color_; 119 return color_;
82 } 120 }
83 121
84 void BubbleDelegateView::Init() {} 122 void BubbleDelegateView::Init() {}
85 123
86 void BubbleDelegateView::StartFade(bool fade_in) { 124 void BubbleDelegateView::StartFade(bool fade_in) {
87 fade_animation_.reset(new ui::SlideAnimation(this)); 125 fade_animation_.reset(new ui::SlideAnimation(this));
88 fade_animation_->SetSlideDuration(kHideFadeDurationMS); 126 fade_animation_->SetSlideDuration(kHideFadeDurationMS);
89 fade_animation_->Reset(fade_in ? 0.0 : 1.0); 127 fade_animation_->Reset(fade_in ? 0.0 : 1.0);
128
129 //// TODO(msw): Better transparency
130 //HWND hwnd = GetWidget()->GetNativeView();
131 //SetWindowLong(hwnd, GWL_EXSTYLE,
132 // GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
133
90 if (fade_in) { 134 if (fade_in) {
91 GetWidget()->SetOpacity(0); 135 border_widget_->SetOpacity(0);
136 border_widget_->Show();
137
138 // TODO(msw): Better transparency like GetWidget()->SetOpacity(0);
139 HWND hwnd = GetWidget()->GetNativeView();
140 SetLayeredWindowAttributes(hwnd, 0, 0, LWA_ALPHA);
92 GetWidget()->Show(); 141 GetWidget()->Show();
142
93 fade_animation_->Show(); 143 fade_animation_->Show();
94 } else { 144 } else {
95 fade_animation_->Hide(); 145 fade_animation_->Hide();
96 } 146 }
97 } 147 }
98 148
99 bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { 149 bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) {
100 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) 150 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
101 return false; 151 return false;
102 if (fade_animation_.get()) 152 if (fade_animation_.get())
103 fade_animation_->Reset(); 153 fade_animation_->Reset();
104 GetWidget()->Close(); 154 GetWidget()->Close();
105 return true; 155 return true;
106 } 156 }
107 157
108 void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) { 158 void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) {
109 DCHECK_EQ(animation, fade_animation_.get()); 159 DCHECK_EQ(animation, fade_animation_.get());
110 bool closed = fade_animation_->GetCurrentValue() == 0; 160 bool closed = fade_animation_->GetCurrentValue() == 0;
111 fade_animation_->Reset(); 161 fade_animation_->Reset();
162
163 //// TODO(msw): Better transparency
164 //HWND hwnd = GetWidget()->GetNativeView();
165 //SetWindowLong(hwnd, GWL_EXSTYLE,
166 // GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
167
112 if (closed) 168 if (closed)
113 GetWidget()->Close(); 169 GetWidget()->Close();
114 } 170 }
115 171
116 void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) { 172 void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) {
117 DCHECK_EQ(animation, fade_animation_.get()); 173 DCHECK_EQ(animation, fade_animation_.get());
118 DCHECK(fade_animation_->is_animating()); 174 DCHECK(fade_animation_->is_animating());
119 GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255); 175 unsigned char opacity = fade_animation_->GetCurrentValue() * 255;
176
177 // TODO(msw): Better transparency like GetWidget()->SetOpacity(opacity);
178 HWND hwnd = GetWidget()->GetNativeView();
179 SetLayeredWindowAttributes(hwnd, 0, opacity, LWA_ALPHA);
180
181 border_widget_->SetOpacity(opacity);
182 border_widget_->non_client_view()->SchedulePaint();
120 SchedulePaint(); 183 SchedulePaint();
121 } 184 }
122 185
123 const BubbleView* BubbleDelegateView::GetBubbleView() const { 186 const BubbleView* BubbleDelegateView::GetBubbleView() const {
124 return GetWidget()->client_view()->AsBubbleView(); 187 return GetWidget()->client_view()->AsBubbleView();
125 } 188 }
126 189
127 const BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { 190 const BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const {
128 return static_cast<BubbleFrameView*>( 191 return static_cast<BubbleFrameView*>(
129 GetWidget()->non_client_view()->frame_view()); 192 border_widget_->non_client_view()->frame_view());
130 } 193 }
131 194
132 gfx::Rect BubbleDelegateView::GetBubbleBounds() { 195 gfx::Rect BubbleDelegateView::GetBubbleBounds() {
133 // The argument rect has its origin at the bubble's arrow anchor point; 196 // The argument rect has its origin at the bubble's arrow anchor point;
134 // its size is the preferred size of the bubble's client view (this view). 197 // its size is the preferred size of the bubble's client view (this view).
135 return GetBubbleFrameView()->GetWindowBoundsForClientBounds( 198 return GetBubbleFrameView()->GetWindowBoundsForClientBounds(
136 gfx::Rect(GetAnchorPoint(), GetPreferredSize())); 199 gfx::Rect(GetAnchorPoint(), GetPreferredSize()));
137 } 200 }
138 201
202 BubbleBorderDelegateView::BubbleBorderDelegateView(BubbleDelegateView* bubble)
203 : bubble_(bubble) {}
204
205 BubbleBorderDelegateView::~BubbleBorderDelegateView() {}
206
207 View* BubbleBorderDelegateView::GetContentsView() {
208 return this;
209 }
210
211 ClientView* BubbleBorderDelegateView::CreateClientView(Widget* widget) {
212 return new ClientView(widget, GetContentsView());
213 }
214
215 NonClientFrameView* BubbleBorderDelegateView::CreateNonClientFrameView() {
216 return new BubbleFrameView(bubble_->GetArrowLocation(),
217 bubble_->GetPreferredSize(),
218 bubble_->GetColor());
219 }
220
139 } // namespace views 221 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698