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

Side by Side Diff: chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc

Issue 7349021: Convert some more view methods to the ui/views style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 9 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
10 #include "chrome/browser/instant/instant_confirm_dialog.h" 10 #include "chrome/browser/instant/instant_confirm_dialog.h"
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 size_animation_.GetCurrentValue() * total_height_delta - 0.5); 267 size_animation_.GetCurrentValue() * total_height_delta - 0.5);
268 current_frame_bounds.set_height( 268 current_frame_bounds.set_height(
269 current_frame_bounds.height() + current_height_delta); 269 current_frame_bounds.height() + current_height_delta);
270 return current_frame_bounds; 270 return current_frame_bounds;
271 } 271 }
272 272
273 void AutocompletePopupContentsView::LayoutChildren() { 273 void AutocompletePopupContentsView::LayoutChildren() {
274 gfx::Rect contents_rect = GetContentsBounds(); 274 gfx::Rect contents_rect = GetContentsBounds();
275 int top = contents_rect.y(); 275 int top = contents_rect.y();
276 for (int i = 0; i < child_count(); ++i) { 276 for (int i = 0; i < child_count(); ++i) {
277 View* v = GetChildViewAt(i); 277 View* v = child_at(i);
278 if (v->IsVisible()) { 278 if (v->IsVisible()) {
279 v->SetBounds(contents_rect.x(), top, contents_rect.width(), 279 v->SetBounds(contents_rect.x(), top, contents_rect.width(),
280 v->GetPreferredSize().height()); 280 v->GetPreferredSize().height());
281 top = v->bounds().bottom(); 281 top = v->bounds().bottom();
282 } 282 }
283 } 283 }
284 } 284 }
285 285
286 //////////////////////////////////////////////////////////////////////////////// 286 ////////////////////////////////////////////////////////////////////////////////
287 // AutocompletePopupContentsView, AutocompletePopupView overrides: 287 // AutocompletePopupContentsView, AutocompletePopupView overrides:
288 288
289 bool AutocompletePopupContentsView::IsOpen() const { 289 bool AutocompletePopupContentsView::IsOpen() const {
290 return (popup_ != NULL); 290 return (popup_ != NULL);
291 } 291 }
292 292
293 void AutocompletePopupContentsView::InvalidateLine(size_t line) { 293 void AutocompletePopupContentsView::InvalidateLine(size_t line) {
294 GetChildViewAt(static_cast<int>(line))->SchedulePaint(); 294 child_at(static_cast<int>(line))->SchedulePaint();
295 } 295 }
296 296
297 void AutocompletePopupContentsView::UpdatePopupAppearance() { 297 void AutocompletePopupContentsView::UpdatePopupAppearance() {
298 if (model_->result().empty()) { 298 if (model_->result().empty()) {
299 // No matches, close any existing popup. 299 // No matches, close any existing popup.
300 if (popup_ != NULL) { 300 if (popup_ != NULL) {
301 size_animation_.Stop(); 301 size_animation_.Stop();
302 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack 302 // NOTE: Do NOT use CloseNow() here, as we may be deep in a callstack
303 // triggered by the popup receiving a message (e.g. LBUTTONUP), and 303 // triggered by the popup receiving a message (e.g. LBUTTONUP), and
304 // destroying the popup would cause us to read garbage when we unwind back 304 // destroying the popup would cause us to read garbage when we unwind back
(...skipping 11 matching lines...) Expand all
316 DCHECK(child_rv_count > 0); 316 DCHECK(child_rv_count > 0);
317 child_rv_count--; 317 child_rv_count--;
318 } 318 }
319 for (size_t i = 0; i < model_->result().size(); ++i) { 319 for (size_t i = 0; i < model_->result().size(); ++i) {
320 AutocompleteResultView* result_view; 320 AutocompleteResultView* result_view;
321 if (i >= child_rv_count) { 321 if (i >= child_rv_count) {
322 result_view = 322 result_view =
323 CreateResultView(this, i, result_font_, result_bold_font_); 323 CreateResultView(this, i, result_font_, result_bold_font_);
324 AddChildViewAt(result_view, static_cast<int>(i)); 324 AddChildViewAt(result_view, static_cast<int>(i));
325 } else { 325 } else {
326 result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); 326 result_view = static_cast<AutocompleteResultView*>(child_at(i));
327 result_view->SetVisible(true); 327 result_view->SetVisible(true);
328 } 328 }
329 result_view->SetMatch(GetMatchAtIndex(i)); 329 result_view->SetMatch(GetMatchAtIndex(i));
330 } 330 }
331 for (size_t i = model_->result().size(); i < child_rv_count; ++i) 331 for (size_t i = model_->result().size(); i < child_rv_count; ++i)
332 GetChildViewAt(i)->SetVisible(false); 332 child_at(i)->SetVisible(false);
333 333
334 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 334 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
335 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) { 335 if (!opt_in_view_ && counter && counter->ShouldShow(base::Time::Now())) {
336 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_); 336 opt_in_view_ = new InstantOptInView(this, result_bold_font_, result_font_);
337 AddChildView(opt_in_view_); 337 AddChildView(opt_in_view_);
338 } else if (opt_in_view_ && (!counter || 338 } else if (opt_in_view_ && (!counter ||
339 !counter->ShouldShow(base::Time::Now()))) { 339 !counter->ShouldShow(base::Time::Now()))) {
340 delete opt_in_view_; 340 delete opt_in_view_;
341 opt_in_view_ = NULL; 341 opt_in_view_ = NULL;
342 } 342 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) { 508 void AutocompletePopupContentsView::PaintResultViews(gfx::CanvasSkia* canvas) {
509 canvas->drawColor(AutocompleteResultView::GetColor( 509 canvas->drawColor(AutocompleteResultView::GetColor(
510 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND)); 510 AutocompleteResultView::NORMAL, AutocompleteResultView::BACKGROUND));
511 View::PaintChildren(canvas); 511 View::PaintChildren(canvas);
512 } 512 }
513 513
514 int AutocompletePopupContentsView::CalculatePopupHeight() { 514 int AutocompletePopupContentsView::CalculatePopupHeight() {
515 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size()); 515 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
516 int popup_height = 0; 516 int popup_height = 0;
517 for (size_t i = 0; i < model_->result().size(); ++i) 517 for (size_t i = 0; i < model_->result().size(); ++i)
518 popup_height += GetChildViewAt(i)->GetPreferredSize().height(); 518 popup_height += child_at(i)->GetPreferredSize().height();
519 return popup_height + 519 return popup_height +
520 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0); 520 (opt_in_view_ ? opt_in_view_->GetPreferredSize().height() : 0);
521 } 521 }
522 522
523 AutocompleteResultView* AutocompletePopupContentsView::CreateResultView( 523 AutocompleteResultView* AutocompletePopupContentsView::CreateResultView(
524 AutocompleteResultViewModel* model, 524 AutocompleteResultViewModel* model,
525 int model_index, 525 int model_index,
526 const gfx::Font& font, 526 const gfx::Font& font,
527 const gfx::Font& bold_font) { 527 const gfx::Font& bold_font) {
528 return new AutocompleteResultView(model, model_index, font, bold_font); 528 return new AutocompleteResultView(model, model_index, font, bold_font);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 652 }
653 653
654 size_t AutocompletePopupContentsView::GetIndexForPoint( 654 size_t AutocompletePopupContentsView::GetIndexForPoint(
655 const gfx::Point& point) { 655 const gfx::Point& point) {
656 if (!HitTest(point)) 656 if (!HitTest(point))
657 return AutocompletePopupModel::kNoMatch; 657 return AutocompletePopupModel::kNoMatch;
658 658
659 int nb_match = model_->result().size(); 659 int nb_match = model_->result().size();
660 DCHECK(nb_match <= child_count()); 660 DCHECK(nb_match <= child_count());
661 for (int i = 0; i < nb_match; ++i) { 661 for (int i = 0; i < nb_match; ++i) {
662 views::View* child = GetChildViewAt(i); 662 views::View* child = child_at(i);
663 gfx::Point point_in_child_coords(point); 663 gfx::Point point_in_child_coords(point);
664 View::ConvertPointToView(this, child, &point_in_child_coords); 664 View::ConvertPointToView(this, child, &point_in_child_coords);
665 if (child->HitTest(point_in_child_coords)) 665 if (child->HitTest(point_in_child_coords))
666 return i; 666 return i;
667 } 667 }
668 return AutocompletePopupModel::kNoMatch; 668 return AutocompletePopupModel::kNoMatch;
669 } 669 }
670 670
671 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) { 671 gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) {
672 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds()); 672 gfx::Rect location_bar_bounds(location_bar_->GetContentsBounds());
(...skipping 23 matching lines...) Expand all
696 opt_in_view_ = NULL; 696 opt_in_view_ = NULL;
697 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); 697 PromoCounter* counter = model_->profile()->GetInstantPromoCounter();
698 DCHECK(counter); 698 DCHECK(counter);
699 counter->Hide(); 699 counter->Hide();
700 if (opt_in) { 700 if (opt_in) {
701 browser::ShowInstantConfirmDialogIfNecessary( 701 browser::ShowInstantConfirmDialogIfNecessary(
702 location_bar_->GetWidget()->GetNativeWindow(), model_->profile()); 702 location_bar_->GetWidget()->GetNativeWindow(), model_->profile());
703 } 703 }
704 UpdatePopupAppearance(); 704 UpdatePopupAppearance();
705 } 705 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698