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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc

Issue 1909263002: Replace safe-bool idiom with explicit WeakPtr::operator bool() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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 (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 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }; 44 };
45 45
46 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
47 // OmniboxPopupContentsView, public: 47 // OmniboxPopupContentsView, public:
48 48
49 OmniboxPopupView* OmniboxPopupContentsView::Create( 49 OmniboxPopupView* OmniboxPopupContentsView::Create(
50 const gfx::FontList& font_list, 50 const gfx::FontList& font_list,
51 OmniboxView* omnibox_view, 51 OmniboxView* omnibox_view,
52 OmniboxEditModel* edit_model, 52 OmniboxEditModel* edit_model,
53 LocationBarView* location_bar_view) { 53 LocationBarView* location_bar_view) {
54 OmniboxPopupContentsView* view = NULL; 54 OmniboxPopupContentsView* view = nullptr;
55 view = new OmniboxPopupContentsView( 55 view = new OmniboxPopupContentsView(
56 font_list, omnibox_view, edit_model, location_bar_view); 56 font_list, omnibox_view, edit_model, location_bar_view);
57 view->Init(); 57 view->Init();
58 return view; 58 return view;
59 } 59 }
60 60
61 OmniboxPopupContentsView::OmniboxPopupContentsView( 61 OmniboxPopupContentsView::OmniboxPopupContentsView(
62 const gfx::FontList& font_list, 62 const gfx::FontList& font_list,
63 OmniboxView* omnibox_view, 63 OmniboxView* omnibox_view,
64 OmniboxEditModel* edit_model, 64 OmniboxEditModel* edit_model,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 v->GetPreferredSize().height()); 139 v->GetPreferredSize().height());
140 top = v->bounds().bottom(); 140 top = v->bounds().bottom();
141 } 141 }
142 } 142 }
143 } 143 }
144 144
145 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
146 // OmniboxPopupContentsView, OmniboxPopupView overrides: 146 // OmniboxPopupContentsView, OmniboxPopupView overrides:
147 147
148 bool OmniboxPopupContentsView::IsOpen() const { 148 bool OmniboxPopupContentsView::IsOpen() const {
149 return popup_ != NULL; 149 return !!popup_;
Nico 2016/06/02 21:31:02 no !! please
Wez 2016/06/02 21:48:06 Opted to use !! based on mmenke@'s points in comme
150 } 150 }
151 151
152 void OmniboxPopupContentsView::InvalidateLine(size_t line) { 152 void OmniboxPopupContentsView::InvalidateLine(size_t line) {
153 OmniboxResultView* result = result_view_at(line); 153 OmniboxResultView* result = result_view_at(line);
154 result->Invalidate(); 154 result->Invalidate();
155 155
156 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) { 156 if (HasMatchAt(line) && GetMatchAtIndex(line).associated_keyword.get()) {
157 result->ShowKeyword(IsSelectedIndex(line) && 157 result->ShowKeyword(IsSelectedIndex(line) &&
158 model_->selected_line_state() == OmniboxPopupModel::KEYWORD); 158 model_->selected_line_state() == OmniboxPopupModel::KEYWORD);
159 } 159 }
160 } 160 }
161 161
162 void OmniboxPopupContentsView::OnLineSelected(size_t line) { 162 void OmniboxPopupContentsView::OnLineSelected(size_t line) {
163 result_view_at(line)->OnSelected(); 163 result_view_at(line)->OnSelected();
164 } 164 }
165 165
166 void OmniboxPopupContentsView::UpdatePopupAppearance() { 166 void OmniboxPopupContentsView::UpdatePopupAppearance() {
167 if (model_->result().empty() || omnibox_view_->IsImeShowingPopup()) { 167 if (model_->result().empty() || omnibox_view_->IsImeShowingPopup()) {
168 // No matches or the IME is showing a popup window which may overlap 168 // No matches or the IME is showing a popup window which may overlap
169 // the omnibox popup window. Close any existing popup. 169 // the omnibox popup window. Close any existing popup.
170 if (popup_ != NULL) { 170 if (popup_) {
171 size_animation_.Stop(); 171 size_animation_.Stop();
172 172
173 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 173 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack
174 // triggered by the popup receiving a message (e.g. LBUTTONUP), and 174 // triggered by the popup receiving a message (e.g. LBUTTONUP), and
175 // destroying the popup would cause us to read garbage when we unwind back 175 // destroying the popup would cause us to read garbage when we unwind back
176 // to that level. 176 // to that level.
177 popup_->Close(); // This will eventually delete the popup. 177 popup_->Close(); // This will eventually delete the popup.
178 popup_.reset(); 178 popup_.reset();
179 } 179 }
180 return; 180 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 gfx::Size(width, CalculatePopupHeight())); 230 gfx::Size(width, CalculatePopupHeight()));
231 231
232 // If we're animating and our target height changes, reset the animation. 232 // If we're animating and our target height changes, reset the animation.
233 // NOTE: If we just reset blindly on _every_ update, then when the user types 233 // NOTE: If we just reset blindly on _every_ update, then when the user types
234 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the 234 // rapidly we could get "stuck" trying repeatedly to animate shrinking by the
235 // last few pixels to get to one visible result. 235 // last few pixels to get to one visible result.
236 if (new_target_bounds.height() != target_bounds_.height()) 236 if (new_target_bounds.height() != target_bounds_.height())
237 size_animation_.Reset(); 237 size_animation_.Reset();
238 target_bounds_ = new_target_bounds; 238 target_bounds_ = new_target_bounds;
239 239
240 if (popup_ == NULL) { 240 if (!popup_) {
241 views::Widget* popup_parent = location_bar_view_->GetWidget(); 241 views::Widget* popup_parent = location_bar_view_->GetWidget();
242 242
243 // If the popup is currently closed, we need to create it. 243 // If the popup is currently closed, we need to create it.
244 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr(); 244 popup_ = (new AutocompletePopupWidget(popup_parent))->AsWeakPtr();
245 245
246 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 246 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
247 #if defined(OS_WIN) 247 #if defined(OS_WIN)
248 // On Windows use the software compositor to ensure that we don't block 248 // On Windows use the software compositor to ensure that we don't block
249 // the UI thread blocking issue during command buffer creation. We can 249 // the UI thread blocking issue during command buffer creation. We can
250 // revert this change once http://crbug.com/125248 is fixed. 250 // revert this change once http://crbug.com/125248 is fixed.
251 params.force_software_compositing = true; 251 params.force_software_compositing = true;
252 #endif 252 #endif
253 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 253 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
254 params.parent = popup_parent->GetNativeView(); 254 params.parent = popup_parent->GetNativeView();
255 params.bounds = GetPopupBounds(); 255 params.bounds = GetPopupBounds();
256 params.context = popup_parent->GetNativeWindow(); 256 params.context = popup_parent->GetNativeWindow();
257 popup_->Init(params); 257 popup_->Init(params);
258 // Third-party software such as DigitalPersona identity verification can 258 // Third-party software such as DigitalPersona identity verification can
259 // hook the underlying window creation methods and use SendMessage to 259 // hook the underlying window creation methods and use SendMessage to
260 // synchronously change focus/activation, resulting in the popup being 260 // synchronously change focus/activation, resulting in the popup being
261 // destroyed by the time control returns here. Bail out in this case to 261 // destroyed by the time control returns here. Bail out in this case to
262 // avoid a NULL dereference. 262 // avoid a NULL dereference.
263 if (!popup_.get()) 263 if (!popup_)
264 return; 264 return;
265 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); 265 popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
266 popup_->SetContentsView(this); 266 popup_->SetContentsView(this);
267 popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup()); 267 popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup());
268 if (!popup_.get()) { 268 if (!popup_) {
269 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose 269 // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose
270 // focus, thereby closing (and destroying) the popup. 270 // focus, thereby closing (and destroying) the popup.
271 // TODO(sky): this won't be needed once we close the omnibox on input 271 // TODO(sky): this won't be needed once we close the omnibox on input
272 // window showing. 272 // window showing.
273 return; 273 return;
274 } 274 }
275 popup_->ShowInactive(); 275 popup_->ShowInactive();
276 } else { 276 } else {
277 // Animate the popup shrinking, but don't animate growing larger since that 277 // Animate the popup shrinking, but don't animate growing larger since that
278 // would make the popup feel less responsive. 278 // would make the popup feel less responsive.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const AutocompleteMatch& match) const { 321 const AutocompleteMatch& match) const {
322 return model_->IsStarredMatch(match); 322 return model_->IsStarredMatch(match);
323 } 323 }
324 324
325 //////////////////////////////////////////////////////////////////////////////// 325 ////////////////////////////////////////////////////////////////////////////////
326 // OmniboxPopupContentsView, AnimationDelegate implementation: 326 // OmniboxPopupContentsView, AnimationDelegate implementation:
327 327
328 void OmniboxPopupContentsView::AnimationProgressed( 328 void OmniboxPopupContentsView::AnimationProgressed(
329 const gfx::Animation* animation) { 329 const gfx::Animation* animation) {
330 // We should only be running the animation when the popup is already visible. 330 // We should only be running the animation when the popup is already visible.
331 DCHECK(popup_ != NULL); 331 DCHECK(popup_);
332 popup_->SetBounds(GetPopupBounds()); 332 popup_->SetBounds(GetPopupBounds());
333 } 333 }
334 334
335 //////////////////////////////////////////////////////////////////////////////// 335 ////////////////////////////////////////////////////////////////////////////////
336 // OmniboxPopupContentsView, views::View overrides: 336 // OmniboxPopupContentsView, views::View overrides:
337 337
338 void OmniboxPopupContentsView::Layout() { 338 void OmniboxPopupContentsView::Layout() {
339 // Size our children to the available content area. 339 // Size our children to the available content area.
340 LayoutChildren(); 340 LayoutChildren();
341 341
342 // We need to manually schedule a paint here since we are a layered window and 342 // We need to manually schedule a paint here since we are a layered window and
343 // won't implicitly require painting until we ask for one. 343 // won't implicitly require painting until we ask for one.
344 SchedulePaint(); 344 SchedulePaint();
345 } 345 }
346 346
347 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint( 347 views::View* OmniboxPopupContentsView::GetTooltipHandlerForPoint(
348 const gfx::Point& point) { 348 const gfx::Point& point) {
349 return NULL; 349 return nullptr;
350 } 350 }
351 351
352 bool OmniboxPopupContentsView::OnMousePressed( 352 bool OmniboxPopupContentsView::OnMousePressed(
353 const ui::MouseEvent& event) { 353 const ui::MouseEvent& event) {
354 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. 354 ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header.
355 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) 355 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton())
356 UpdateLineEvent(event, event.IsLeftMouseButton()); 356 UpdateLineEvent(event, event.IsLeftMouseButton());
357 return true; 357 return true;
358 } 358 }
359 359
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 size_t index = GetIndexForPoint(event.location()); 528 size_t index = GetIndexForPoint(event.location());
529 if (!HasMatchAt(index)) 529 if (!HasMatchAt(index))
530 return; 530 return;
531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition, 531 omnibox_view_->OpenMatch(model_->result().match_at(index), disposition,
532 GURL(), base::string16(), index); 532 GURL(), base::string16(), index);
533 } 533 }
534 534
535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) { 535 OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) {
536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i))); 536 return static_cast<OmniboxResultView*>(child_at(static_cast<int>(i)));
537 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698