| OLD | NEW |
| 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/gtk/tabs/dragged_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/dragged_view_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will | 338 // Blit the rendered bitmap into a pixmap. Any pixel set in the pixmap will |
| 339 // be opaque in the container window. | 339 // be opaque in the container window. |
| 340 if (!attached_) | 340 if (!attached_) |
| 341 cairo_scale(cairo_context, kScalingFactor, kScalingFactor); | 341 cairo_scale(cairo_context, kScalingFactor, kScalingFactor); |
| 342 for (size_t i = 0; i < renderers_.size(); i++) { | 342 for (size_t i = 0; i < renderers_.size(); i++) { |
| 343 if (static_cast<int>(i) == 0) | 343 if (static_cast<int>(i) == 0) |
| 344 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); | 344 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); |
| 345 else | 345 else |
| 346 cairo_set_operator(cairo_context, CAIRO_OPERATOR_OVER); | 346 cairo_set_operator(cairo_context, CAIRO_OPERATOR_OVER); |
| 347 PaintTab(i, container_, cairo_context, container_->allocation.width); | 347 |
| 348 GtkAllocation allocation; |
| 349 gtk_widget_get_allocation(container_, &allocation); |
| 350 PaintTab(i, container_, cairo_context, allocation.width); |
| 348 } | 351 } |
| 349 | 352 |
| 350 if (!attached_) { | 353 if (!attached_) { |
| 351 // Make the render area depiction opaque (leaving enough room for the | 354 // Make the render area depiction opaque (leaving enough room for the |
| 352 // border). | 355 // border). |
| 353 cairo_identity_matrix(cairo_context); | 356 cairo_identity_matrix(cairo_context); |
| 354 // On Lucid running VNC, the X server will reject RGBA (1,1,1,1) as an | 357 // On Lucid running VNC, the X server will reject RGBA (1,1,1,1) as an |
| 355 // invalid value below in gdk_window_shape_combine_mask(). Using (0,0,0,1) | 358 // invalid value below in gdk_window_shape_combine_mask(). Using (0,0,0,1) |
| 356 // instead. The value doesn't really matter, as long as the alpha is not 0. | 359 // instead. The value doesn't really matter, as long as the alpha is not 0. |
| 357 cairo_set_source_rgba(cairo_context, 0.0f, 0.0f, 0.0f, 1.0f); | 360 cairo_set_source_rgba(cairo_context, 0.0f, 0.0f, 0.0f, 1.0f); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 376 | 379 |
| 377 if (ui::IsScreenComposited()) | 380 if (ui::IsScreenComposited()) |
| 378 SetContainerTransparency(); | 381 SetContainerTransparency(); |
| 379 else | 382 else |
| 380 SetContainerShapeMask(); | 383 SetContainerShapeMask(); |
| 381 | 384 |
| 382 // Only used when not attached. | 385 // Only used when not attached. |
| 383 int tab_height = static_cast<int>( | 386 int tab_height = static_cast<int>( |
| 384 kScalingFactor * renderers_[drag_data_->source_tab_index()]->height()); | 387 kScalingFactor * renderers_[drag_data_->source_tab_index()]->height()); |
| 385 | 388 |
| 389 GtkAllocation allocation; |
| 390 gtk_widget_get_allocation(widget, &allocation); |
| 391 |
| 386 // Draw the render area. | 392 // Draw the render area. |
| 387 BackingStore* backing_store = drag_data_->GetSourceTabContents()-> | 393 BackingStore* backing_store = drag_data_->GetSourceTabContents()-> |
| 388 render_view_host()->GetBackingStore(false); | 394 render_view_host()->GetBackingStore(false); |
| 389 if (backing_store && !attached_) { | 395 if (backing_store && !attached_) { |
| 390 // This leaves room for the border. | 396 // This leaves room for the border. |
| 391 static_cast<BackingStoreGtk*>(backing_store)->PaintToRect( | 397 static_cast<BackingStoreGtk*>(backing_store)->PaintToRect( |
| 392 gfx::Rect(kDragFrameBorderSize, tab_height, | 398 gfx::Rect(kDragFrameBorderSize, tab_height, |
| 393 widget->allocation.width - kTwiceDragFrameBorderSize, | 399 allocation.width - kTwiceDragFrameBorderSize, |
| 394 widget->allocation.height - tab_height - | 400 allocation.height - tab_height - |
| 395 kDragFrameBorderSize), | 401 kDragFrameBorderSize), |
| 396 GDK_DRAWABLE(widget->window)); | 402 GDK_DRAWABLE(widget->window)); |
| 397 } | 403 } |
| 398 | 404 |
| 399 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 405 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 400 // Draw the border. | 406 // Draw the border. |
| 401 if (!attached_) { | 407 if (!attached_) { |
| 402 cairo_set_line_width(cr, kDragFrameBorderSize); | 408 cairo_set_line_width(cr, kDragFrameBorderSize); |
| 403 cairo_set_source_rgb(cr, kDraggedTabBorderColor[0], | 409 cairo_set_source_rgb(cr, kDraggedTabBorderColor[0], |
| 404 kDraggedTabBorderColor[1], | 410 kDraggedTabBorderColor[1], |
| 405 kDraggedTabBorderColor[2]); | 411 kDraggedTabBorderColor[2]); |
| 406 // |offset| is the distance from the edge of the image to the middle of | 412 // |offset| is the distance from the edge of the image to the middle of |
| 407 // the border line. | 413 // the border line. |
| 408 double offset = kDragFrameBorderSize / 2.0 - 0.5; | 414 double offset = kDragFrameBorderSize / 2.0 - 0.5; |
| 409 double left_x = offset; | 415 double left_x = offset; |
| 410 double top_y = tab_height - kDragFrameBorderSize + offset; | 416 double top_y = tab_height - kDragFrameBorderSize + offset; |
| 411 double right_x = widget->allocation.width - offset; | 417 double right_x = allocation.width - offset; |
| 412 double bottom_y = widget->allocation.height - offset; | 418 double bottom_y = allocation.height - offset; |
| 413 | 419 |
| 414 cairo_move_to(cr, left_x, top_y); | 420 cairo_move_to(cr, left_x, top_y); |
| 415 cairo_line_to(cr, left_x, bottom_y); | 421 cairo_line_to(cr, left_x, bottom_y); |
| 416 cairo_line_to(cr, right_x, bottom_y); | 422 cairo_line_to(cr, right_x, bottom_y); |
| 417 cairo_line_to(cr, right_x, top_y); | 423 cairo_line_to(cr, right_x, top_y); |
| 418 cairo_line_to(cr, left_x, top_y); | 424 cairo_line_to(cr, left_x, top_y); |
| 419 cairo_stroke(cr); | 425 cairo_stroke(cr); |
| 420 } | 426 } |
| 421 | 427 |
| 422 // Draw the tab. | 428 // Draw the tab. |
| 423 if (!attached_) | 429 if (!attached_) |
| 424 cairo_scale(cr, kScalingFactor, kScalingFactor); | 430 cairo_scale(cr, kScalingFactor, kScalingFactor); |
| 425 // Painting all but the active tab first, from last to first. | 431 // Painting all but the active tab first, from last to first. |
| 426 for (int i = renderers_.size() - 1; i >= 0; i--) { | 432 for (int i = renderers_.size() - 1; i >= 0; i--) { |
| 427 if (i == drag_data_->source_tab_index()) | 433 if (i == drag_data_->source_tab_index()) |
| 428 continue; | 434 continue; |
| 429 PaintTab(i, widget, cr, widget->allocation.width); | 435 PaintTab(i, widget, cr, allocation.width); |
| 430 } | 436 } |
| 431 // Painting the active tab last, so that it appears on top. | 437 // Painting the active tab last, so that it appears on top. |
| 432 PaintTab(drag_data_->source_tab_index(), widget, cr, | 438 PaintTab(drag_data_->source_tab_index(), widget, cr, |
| 433 widget->allocation.width); | 439 allocation.width); |
| 434 | 440 |
| 435 cairo_destroy(cr); | 441 cairo_destroy(cr); |
| 436 | 442 |
| 437 // We've already drawn the tab, so don't propagate the expose-event signal. | 443 // We've already drawn the tab, so don't propagate the expose-event signal. |
| 438 return TRUE; | 444 return TRUE; |
| 439 } | 445 } |
| 440 | 446 |
| 441 void DraggedViewGtk::PaintTab(int index, GtkWidget* widget, cairo_t* cr, | 447 void DraggedViewGtk::PaintTab(int index, GtkWidget* widget, cairo_t* cr, |
| 442 int widget_width) { | 448 int widget_width) { |
| 443 renderers_[index]->set_mini(drag_data_->get(index)->mini_); | 449 renderers_[index]->set_mini(drag_data_->get(index)->mini_); |
| 444 cairo_surface_t* surface = renderers_[index]->PaintToSurface(widget, cr); | 450 cairo_surface_t* surface = renderers_[index]->PaintToSurface(widget, cr); |
| 445 | 451 |
| 446 int paint_at = 0; | 452 int paint_at = 0; |
| 447 if (!base::i18n::IsRTL()) { | 453 if (!base::i18n::IsRTL()) { |
| 448 paint_at = std::max(GetWidthInTabStripFromTo(0, index) - 16, 0); | 454 paint_at = std::max(GetWidthInTabStripFromTo(0, index) - 16, 0); |
| 449 } else { | 455 } else { |
| 450 paint_at = GetTotalWidthInTabStrip() - | 456 paint_at = GetTotalWidthInTabStrip() - |
| 451 GetWidthInTabStripFromTo(0, index + 1); | 457 GetWidthInTabStripFromTo(0, index + 1); |
| 452 if (!attached_) { | 458 if (!attached_) { |
| 453 paint_at = widget_width / kScalingFactor - | 459 paint_at = widget_width / kScalingFactor - |
| 454 GetWidthInTabStripFromTo(0, index + 1); | 460 GetWidthInTabStripFromTo(0, index + 1); |
| 455 } | 461 } |
| 456 } | 462 } |
| 457 | 463 |
| 458 cairo_set_source_surface(cr, surface, paint_at, 0); | 464 cairo_set_source_surface(cr, surface, paint_at, 0); |
| 459 cairo_paint(cr); | 465 cairo_paint(cr); |
| 460 cairo_surface_destroy(surface); | 466 cairo_surface_destroy(surface); |
| 461 } | 467 } |
| OLD | NEW |