| 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 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 delete it->second; | 344 delete it->second; |
| 345 } | 345 } |
| 346 | 346 |
| 347 bool OmniboxPopupViewGtk::IsOpen() const { | 347 bool OmniboxPopupViewGtk::IsOpen() const { |
| 348 return opened_; | 348 return opened_; |
| 349 } | 349 } |
| 350 | 350 |
| 351 void OmniboxPopupViewGtk::InvalidateLine(size_t line) { | 351 void OmniboxPopupViewGtk::InvalidateLine(size_t line) { |
| 352 // TODO(deanm): Is it possible to use some constant for the width, instead | 352 // TODO(deanm): Is it possible to use some constant for the width, instead |
| 353 // of having to query the width of the window? | 353 // of having to query the width of the window? |
| 354 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); |
| 354 GdkRectangle line_rect = GetRectForLine( | 355 GdkRectangle line_rect = GetRectForLine( |
| 355 line, GetWindowRect(window_->window).width()).ToGdkRectangle(); | 356 line, GetWindowRect(gdk_window).width()).ToGdkRectangle(); |
| 356 gdk_window_invalidate_rect(window_->window, &line_rect, FALSE); | 357 gdk_window_invalidate_rect(gdk_window, &line_rect, FALSE); |
| 357 } | 358 } |
| 358 | 359 |
| 359 void OmniboxPopupViewGtk::UpdatePopupAppearance() { | 360 void OmniboxPopupViewGtk::UpdatePopupAppearance() { |
| 360 const AutocompleteResult& result = model_->result(); | 361 const AutocompleteResult& result = model_->result(); |
| 361 if (result.empty()) { | 362 if (result.empty()) { |
| 362 Hide(); | 363 Hide(); |
| 363 return; | 364 return; |
| 364 } | 365 } |
| 365 | 366 |
| 366 Show(result.size()); | 367 Show(result.size()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 378 GtkRequisition req; | 379 GtkRequisition req; |
| 379 gtk_widget_size_request(window_, &req); | 380 gtk_widget_size_request(window_, &req); |
| 380 retval.set_width(req.width); | 381 retval.set_width(req.width); |
| 381 retval.set_height(req.height); | 382 retval.set_height(req.height); |
| 382 | 383 |
| 383 return retval; | 384 return retval; |
| 384 } | 385 } |
| 385 | 386 |
| 386 void OmniboxPopupViewGtk::PaintUpdatesNow() { | 387 void OmniboxPopupViewGtk::PaintUpdatesNow() { |
| 387 // Paint our queued invalidations now, synchronously. | 388 // Paint our queued invalidations now, synchronously. |
| 388 gdk_window_process_updates(window_->window, FALSE); | 389 GdkWindow* gdk_window = gtk_widget_get_window(window_); |
| 390 gdk_window_process_updates(gdk_window, FALSE); |
| 389 } | 391 } |
| 390 | 392 |
| 391 void OmniboxPopupViewGtk::OnDragCanceled() { | 393 void OmniboxPopupViewGtk::OnDragCanceled() { |
| 392 ignore_mouse_drag_ = true; | 394 ignore_mouse_drag_ = true; |
| 393 } | 395 } |
| 394 | 396 |
| 395 void OmniboxPopupViewGtk::Observe(int type, | 397 void OmniboxPopupViewGtk::Observe(int type, |
| 396 const content::NotificationSource& source, | 398 const content::NotificationSource& source, |
| 397 const content::NotificationDetails& details) { | 399 const content::NotificationDetails& details) { |
| 398 DCHECK(type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 400 DCHECK(type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 selected_content_dim_text_color_ = | 434 selected_content_dim_text_color_ = |
| 433 gtk_util::AverageColors(selected_content_text_color_, | 435 gtk_util::AverageColors(selected_content_text_color_, |
| 434 selected_background_color_); | 436 selected_background_color_); |
| 435 | 437 |
| 436 // Set the background color, so we don't need to paint it manually. | 438 // Set the background color, so we don't need to paint it manually. |
| 437 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &background_color_); | 439 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &background_color_); |
| 438 } | 440 } |
| 439 | 441 |
| 440 void OmniboxPopupViewGtk::Show(size_t num_results) { | 442 void OmniboxPopupViewGtk::Show(size_t num_results) { |
| 441 gint origin_x, origin_y; | 443 gint origin_x, origin_y; |
| 442 gdk_window_get_origin(location_bar_->window, &origin_x, &origin_y); | 444 GdkWindow* gdk_window = gtk_widget_get_window(location_bar_); |
| 443 GtkAllocation allocation = location_bar_->allocation; | 445 gdk_window_get_origin(gdk_window, &origin_x, &origin_y); |
| 446 GtkAllocation allocation; |
| 447 gtk_widget_get_allocation(location_bar_, &allocation); |
| 444 | 448 |
| 445 int horizontal_offset = 1; | 449 int horizontal_offset = 1; |
| 446 gtk_window_move(GTK_WINDOW(window_), | 450 gtk_window_move(GTK_WINDOW(window_), |
| 447 origin_x + allocation.x - kBorderThickness + horizontal_offset, | 451 origin_x + allocation.x - kBorderThickness + horizontal_offset, |
| 448 origin_y + allocation.y + allocation.height - kBorderThickness - 1 + | 452 origin_y + allocation.y + allocation.height - kBorderThickness - 1 + |
| 449 kVerticalOffset); | 453 kVerticalOffset); |
| 450 gtk_widget_set_size_request(window_, | 454 gtk_widget_set_size_request(window_, |
| 451 allocation.width + (kBorderThickness * 2) - (horizontal_offset * 2), | 455 allocation.width + (kBorderThickness * 2) - (horizontal_offset * 2), |
| 452 (num_results * kHeightPerResult) + (kBorderThickness * 2)); | 456 (num_results * kHeightPerResult) + (kBorderThickness * 2)); |
| 453 gtk_widget_show(window_); | 457 gtk_widget_show(window_); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 gfx::Rect window_rect = GetWindowRect(event->window); | 584 gfx::Rect window_rect = GetWindowRect(event->window); |
| 581 gfx::Rect damage_rect = gfx::Rect(event->area); | 585 gfx::Rect damage_rect = gfx::Rect(event->area); |
| 582 // Handle when our window is super narrow. A bunch of the calculations | 586 // Handle when our window is super narrow. A bunch of the calculations |
| 583 // below would go negative, and really we're not going to fit anything | 587 // below would go negative, and really we're not going to fit anything |
| 584 // useful in such a small window anyway. Just don't paint anything. | 588 // useful in such a small window anyway. Just don't paint anything. |
| 585 // This means we won't draw the border, but, yeah, whatever. | 589 // This means we won't draw the border, but, yeah, whatever. |
| 586 // TODO(deanm): Make the code more robust and remove this check. | 590 // TODO(deanm): Make the code more robust and remove this check. |
| 587 if (window_rect.width() < (kIconAreaWidth * 3)) | 591 if (window_rect.width() < (kIconAreaWidth * 3)) |
| 588 return TRUE; | 592 return TRUE; |
| 589 | 593 |
| 590 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 594 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget)); |
| 591 gdk_cairo_rectangle(cr, &event->area); | 595 gdk_cairo_rectangle(cr, &event->area); |
| 592 cairo_clip(cr); | 596 cairo_clip(cr); |
| 593 | 597 |
| 594 // This assert is kinda ugly, but it would be more currently unneeded work | 598 // This assert is kinda ugly, but it would be more currently unneeded work |
| 595 // to support painting a border that isn't 1 pixel thick. There is no point | 599 // to support painting a border that isn't 1 pixel thick. There is no point |
| 596 // in writing that code now, and explode if that day ever comes. | 600 // in writing that code now, and explode if that day ever comes. |
| 597 COMPILE_ASSERT(kBorderThickness == 1, border_1px_implied); | 601 COMPILE_ASSERT(kBorderThickness == 1, border_1px_implied); |
| 598 // Draw the 1px border around the entire window. | 602 // Draw the 1px border around the entire window. |
| 599 gdk_cairo_set_source_color(cr, &border_color_); | 603 gdk_cairo_set_source_color(cr, &border_color_); |
| 600 cairo_rectangle(cr, 0, 0, window_rect.width(), window_rect.height()); | 604 cairo_rectangle(cr, 0, 0, window_rect.width(), window_rect.height()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 (actual_description_width / PANGO_SCALE)), | 694 (actual_description_width / PANGO_SCALE)), |
| 691 content_y); | 695 content_y); |
| 692 pango_cairo_show_layout(cr, layout_); | 696 pango_cairo_show_layout(cr, layout_); |
| 693 cairo_restore(cr); | 697 cairo_restore(cr); |
| 694 } | 698 } |
| 695 } | 699 } |
| 696 | 700 |
| 697 cairo_destroy(cr); | 701 cairo_destroy(cr); |
| 698 return TRUE; | 702 return TRUE; |
| 699 } | 703 } |
| OLD | NEW |