| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 attached_ = true; | 136 attached_ = true; |
| 137 parent_window_width_ = window_width; | 137 parent_window_width_ = window_width; |
| 138 normal_width_ = normal_width; | 138 normal_width_ = normal_width; |
| 139 mini_width_ = mini_width; | 139 mini_width_ = mini_width; |
| 140 | 140 |
| 141 int dragged_tab_width = | 141 int dragged_tab_width = |
| 142 drag_data_->GetSourceTabData()->mini_ ? mini_width : normal_width; | 142 drag_data_->GetSourceTabData()->mini_ ? mini_width : normal_width; |
| 143 | 143 |
| 144 Resize(dragged_tab_width); | 144 Resize(dragged_tab_width); |
| 145 | 145 |
| 146 if (ui::IsScreenComposited()) | 146 if (ui::IsScreenComposited()) { |
| 147 gdk_window_set_opacity(container_->window, kOpaqueAlpha); | 147 GdkWindow* gdk_window = gtk_widget_get_window(container_); |
| 148 gdk_window_set_opacity(gdk_window, kOpaqueAlpha); |
| 149 } |
| 148 } | 150 } |
| 149 | 151 |
| 150 void DraggedViewGtk::Resize(int width) { | 152 void DraggedViewGtk::Resize(int width) { |
| 151 attached_tab_size_.set_width(width); | 153 attached_tab_size_.set_width(width); |
| 152 ResizeContainer(); | 154 ResizeContainer(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void DraggedViewGtk::Detach() { | 157 void DraggedViewGtk::Detach() { |
| 156 attached_ = false; | 158 attached_ = false; |
| 157 ResizeContainer(); | 159 ResizeContainer(); |
| 158 | 160 |
| 159 if (ui::IsScreenComposited()) | 161 if (ui::IsScreenComposited()) { |
| 160 gdk_window_set_opacity(container_->window, kTransparentAlpha); | 162 GdkWindow* gdk_window = gtk_widget_get_window(container_); |
| 163 gdk_window_set_opacity(gdk_window, kTransparentAlpha); |
| 164 } |
| 161 } | 165 } |
| 162 | 166 |
| 163 void DraggedViewGtk::Update() { | 167 void DraggedViewGtk::Update() { |
| 164 gtk_widget_queue_draw(container_); | 168 gtk_widget_queue_draw(container_); |
| 165 } | 169 } |
| 166 | 170 |
| 167 int DraggedViewGtk::GetWidthInTabStripFromTo(int from, int to) { | 171 int DraggedViewGtk::GetWidthInTabStripFromTo(int from, int to) { |
| 168 DCHECK(from <= static_cast<int>(drag_data_->size())); | 172 DCHECK(from <= static_cast<int>(drag_data_->size())); |
| 169 DCHECK(to <= static_cast<int>(drag_data_->size())); | 173 DCHECK(to <= static_cast<int>(drag_data_->size())); |
| 170 | 174 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 200 width -= 16; | 204 width -= 16; |
| 201 } | 205 } |
| 202 return width; | 206 return width; |
| 203 } | 207 } |
| 204 | 208 |
| 205 void DraggedViewGtk::AnimateToBounds(const gfx::Rect& bounds, | 209 void DraggedViewGtk::AnimateToBounds(const gfx::Rect& bounds, |
| 206 const base::Closure& callback) { | 210 const base::Closure& callback) { |
| 207 animation_callback_ = callback; | 211 animation_callback_ = callback; |
| 208 | 212 |
| 209 gint x, y, width, height; | 213 gint x, y, width, height; |
| 210 gdk_window_get_origin(container_->window, &x, &y); | 214 GdkWindow* gdk_window = gtk_widget_get_window(container_); |
| 211 gdk_window_get_geometry(container_->window, NULL, NULL, | 215 gdk_window_get_origin(gdk_window, &x, &y); |
| 216 gdk_window_get_geometry(gdk_window, NULL, NULL, |
| 212 &width, &height, NULL); | 217 &width, &height, NULL); |
| 213 | 218 |
| 214 animation_start_bounds_ = gfx::Rect(x, y, width, height); | 219 animation_start_bounds_ = gfx::Rect(x, y, width, height); |
| 215 animation_end_bounds_ = bounds; | 220 animation_end_bounds_ = bounds; |
| 216 | 221 |
| 217 close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); | 222 close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); |
| 218 close_animation_.SetTweenType(ui::Tween::EASE_OUT); | 223 close_animation_.SetTweenType(ui::Tween::EASE_OUT); |
| 219 if (!close_animation_.IsShowing()) { | 224 if (!close_animation_.IsShowing()) { |
| 220 close_animation_.Reset(); | 225 close_animation_.Reset(); |
| 221 close_animation_.Show(); | 226 close_animation_.Show(); |
| 222 } | 227 } |
| 223 } | 228 } |
| 224 | 229 |
| 225 //////////////////////////////////////////////////////////////////////////////// | 230 //////////////////////////////////////////////////////////////////////////////// |
| 226 // DraggedViewGtk, ui::AnimationDelegate implementation: | 231 // DraggedViewGtk, ui::AnimationDelegate implementation: |
| 227 | 232 |
| 228 void DraggedViewGtk::AnimationProgressed(const ui::Animation* animation) { | 233 void DraggedViewGtk::AnimationProgressed(const ui::Animation* animation) { |
| 229 int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x()); | 234 int delta_x = (animation_end_bounds_.x() - animation_start_bounds_.x()); |
| 230 int x = animation_start_bounds_.x() + | 235 int x = animation_start_bounds_.x() + |
| 231 static_cast<int>(delta_x * animation->GetCurrentValue()); | 236 static_cast<int>(delta_x * animation->GetCurrentValue()); |
| 232 int y = animation_end_bounds_.y(); | 237 int y = animation_end_bounds_.y(); |
| 233 gdk_window_move(container_->window, x, y); | 238 GdkWindow* gdk_window = gtk_widget_get_window(container_); |
| 239 gdk_window_move(gdk_window, x, y); |
| 234 } | 240 } |
| 235 | 241 |
| 236 void DraggedViewGtk::AnimationEnded(const ui::Animation* animation) { | 242 void DraggedViewGtk::AnimationEnded(const ui::Animation* animation) { |
| 237 animation_callback_.Run(); | 243 animation_callback_.Run(); |
| 238 } | 244 } |
| 239 | 245 |
| 240 void DraggedViewGtk::AnimationCanceled(const ui::Animation* animation) { | 246 void DraggedViewGtk::AnimationCanceled(const ui::Animation* animation) { |
| 241 AnimationEnded(animation); | 247 AnimationEnded(animation); |
| 242 } | 248 } |
| 243 | 249 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); | 312 GdkColormap* colormap = gdk_screen_get_rgba_colormap(screen); |
| 307 | 313 |
| 308 // If rgba is not available, use rgb instead. | 314 // If rgba is not available, use rgb instead. |
| 309 if (!colormap) | 315 if (!colormap) |
| 310 colormap = gdk_screen_get_rgb_colormap(screen); | 316 colormap = gdk_screen_get_rgb_colormap(screen); |
| 311 | 317 |
| 312 gtk_widget_set_colormap(container_, colormap); | 318 gtk_widget_set_colormap(container_, colormap); |
| 313 } | 319 } |
| 314 | 320 |
| 315 void DraggedViewGtk::SetContainerTransparency() { | 321 void DraggedViewGtk::SetContainerTransparency() { |
| 316 cairo_t* cairo_context = gdk_cairo_create(container_->window); | 322 cairo_t* cairo_context = gdk_cairo_create(gtk_widget_get_window(container_)); |
| 317 if (!cairo_context) | 323 if (!cairo_context) |
| 318 return; | 324 return; |
| 319 | 325 |
| 320 // Make the background of the dragged tab window fully transparent. All of | 326 // Make the background of the dragged tab window fully transparent. All of |
| 321 // the content of the window (child widgets) will be completely opaque. | 327 // the content of the window (child widgets) will be completely opaque. |
| 322 gfx::Size size = bounds().size(); | 328 gfx::Size size = bounds().size(); |
| 323 cairo_scale(cairo_context, static_cast<double>(size.width()), | 329 cairo_scale(cairo_context, static_cast<double>(size.width()), |
| 324 static_cast<double>(size.height())); | 330 static_cast<double>(size.height())); |
| 325 cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f); | 331 cairo_set_source_rgba(cairo_context, 1.0f, 1.0f, 1.0f, 0.0f); |
| 326 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); | 332 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 kDragFrameBorderSize); | 371 kDragFrameBorderSize); |
| 366 cairo_rectangle(cairo_context, | 372 cairo_rectangle(cairo_context, |
| 367 0, tab_height, | 373 0, tab_height, |
| 368 size.width(), size.height() - tab_height); | 374 size.width(), size.height() - tab_height); |
| 369 cairo_fill(cairo_context); | 375 cairo_fill(cairo_context); |
| 370 } | 376 } |
| 371 | 377 |
| 372 cairo_destroy(cairo_context); | 378 cairo_destroy(cairo_context); |
| 373 | 379 |
| 374 // Set the shape mask. | 380 // Set the shape mask. |
| 375 gdk_window_shape_combine_mask(container_->window, pixmap, 0, 0); | 381 GdkWindow* gdk_window = gtk_widget_get_window(container_); |
| 382 gdk_window_shape_combine_mask(gdk_window, pixmap, 0, 0); |
| 376 g_object_unref(pixmap); | 383 g_object_unref(pixmap); |
| 377 } | 384 } |
| 378 | 385 |
| 379 gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { | 386 gboolean DraggedViewGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event) { |
| 380 TRACE_EVENT0("ui::gtk", "DraggedViewGtk::OnExpose"); | 387 TRACE_EVENT0("ui::gtk", "DraggedViewGtk::OnExpose"); |
| 381 | 388 |
| 382 if (ui::IsScreenComposited()) | 389 if (ui::IsScreenComposited()) |
| 383 SetContainerTransparency(); | 390 SetContainerTransparency(); |
| 384 else | 391 else |
| 385 SetContainerShapeMask(); | 392 SetContainerShapeMask(); |
| 386 | 393 |
| 387 // Only used when not attached. | 394 // Only used when not attached. |
| 388 int tab_height = static_cast<int>( | 395 int tab_height = static_cast<int>( |
| 389 kScalingFactor * renderers_[drag_data_->source_tab_index()]->height()); | 396 kScalingFactor * renderers_[drag_data_->source_tab_index()]->height()); |
| 390 | 397 |
| 391 GtkAllocation allocation; | 398 GtkAllocation allocation; |
| 392 gtk_widget_get_allocation(widget, &allocation); | 399 gtk_widget_get_allocation(widget, &allocation); |
| 393 | 400 |
| 394 // Draw the render area. | 401 // Draw the render area. |
| 395 BackingStore* backing_store = drag_data_->GetSourceWebContents()-> | 402 BackingStore* backing_store = drag_data_->GetSourceWebContents()-> |
| 396 GetRenderViewHost()->GetBackingStore(false); | 403 GetRenderViewHost()->GetBackingStore(false); |
| 397 if (backing_store && !attached_) { | 404 if (backing_store && !attached_) { |
| 398 // This leaves room for the border. | 405 // This leaves room for the border. |
| 399 static_cast<BackingStoreGtk*>(backing_store)->PaintToRect( | 406 static_cast<BackingStoreGtk*>(backing_store)->PaintToRect( |
| 400 gfx::Rect(kDragFrameBorderSize, tab_height, | 407 gfx::Rect(kDragFrameBorderSize, tab_height, |
| 401 allocation.width - kTwiceDragFrameBorderSize, | 408 allocation.width - kTwiceDragFrameBorderSize, |
| 402 allocation.height - tab_height - | 409 allocation.height - tab_height - |
| 403 kDragFrameBorderSize), | 410 kDragFrameBorderSize), |
| 404 GDK_DRAWABLE(widget->window)); | 411 GDK_DRAWABLE(gtk_widget_get_window(widget))); |
| 405 } | 412 } |
| 406 | 413 |
| 407 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 414 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget)); |
| 408 // Draw the border. | 415 // Draw the border. |
| 409 if (!attached_) { | 416 if (!attached_) { |
| 410 cairo_set_line_width(cr, kDragFrameBorderSize); | 417 cairo_set_line_width(cr, kDragFrameBorderSize); |
| 411 cairo_set_source_rgb(cr, kDraggedTabBorderColor[0], | 418 cairo_set_source_rgb(cr, kDraggedTabBorderColor[0], |
| 412 kDraggedTabBorderColor[1], | 419 kDraggedTabBorderColor[1], |
| 413 kDraggedTabBorderColor[2]); | 420 kDraggedTabBorderColor[2]); |
| 414 // |offset| is the distance from the edge of the image to the middle of | 421 // |offset| is the distance from the edge of the image to the middle of |
| 415 // the border line. | 422 // the border line. |
| 416 double offset = kDragFrameBorderSize / 2.0 - 0.5; | 423 double offset = kDragFrameBorderSize / 2.0 - 0.5; |
| 417 double left_x = offset; | 424 double left_x = offset; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 if (!attached_) { | 467 if (!attached_) { |
| 461 paint_at = widget_width / kScalingFactor - | 468 paint_at = widget_width / kScalingFactor - |
| 462 GetWidthInTabStripFromTo(0, index + 1); | 469 GetWidthInTabStripFromTo(0, index + 1); |
| 463 } | 470 } |
| 464 } | 471 } |
| 465 | 472 |
| 466 cairo_set_source_surface(cr, surface, paint_at, 0); | 473 cairo_set_source_surface(cr, surface, paint_at, 0); |
| 467 cairo_paint(cr); | 474 cairo_paint(cr); |
| 468 cairo_surface_destroy(surface); | 475 cairo_surface_destroy(surface); |
| 469 } | 476 } |
| OLD | NEW |