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

Side by Side Diff: chrome/browser/gtk/tabs/tab_strip_gtk.cc

Issue 62133: Fix a crash on tab closure. We now use our own model data and check that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/tabs/tab_strip_gtk.h" 5 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
6 6
7 #include "base/gfx/gtk_util.h" 7 #include "base/gfx/gtk_util.h"
8 #include "base/gfx/point.h" 8 #include "base/gfx/point.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 10 #include "chrome/browser/tab_contents/tab_contents.h"
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // static 428 // static
429 gboolean TabStripGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event, 429 gboolean TabStripGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event,
430 TabStripGtk* tabstrip) { 430 TabStripGtk* tabstrip) {
431 int old_hover_index = tabstrip->hover_index_; 431 int old_hover_index = tabstrip->hover_index_;
432 tabstrip->hover_index_ = -1; 432 tabstrip->hover_index_ = -1;
433 433
434 gfx::Point coord(event->x, event->y); 434 gfx::Point coord(event->x, event->y);
435 // Get a rough estimate for which tab the mouse is over. 435 // Get a rough estimate for which tab the mouse is over.
436 int index = event->x / (tabstrip->current_unselected_width_ + kTabHOffset); 436 int index = event->x / (tabstrip->current_unselected_width_ + kTabHOffset);
437 437
438 if (index >= tabstrip->model_->count()) { 438 int tab_count = tabstrip->GetTabCount();
439 if (old_hover_index != -1) { 439 if (index >= tab_count) {
440 if (old_hover_index != -1 && old_hover_index < tab_count) {
440 tabstrip->GetTabAt(old_hover_index)->SetHovering(false); 441 tabstrip->GetTabAt(old_hover_index)->SetHovering(false);
441 gtk_widget_queue_draw(tabstrip->tabstrip_.get()); 442 gtk_widget_queue_draw(tabstrip->tabstrip_.get());
442 } 443 }
443 444
444 return TRUE; 445 return TRUE;
445 } 446 }
446 447
447 // Tab hovering calcuation. 448 // Tab hovering calcuation.
448 // Using the rough estimate tab index, we check the tab bounds in a smart 449 // Using the rough estimate tab index, we check the tab bounds in a smart
449 // order to reduce the number of tabs we need to check. If the tab at the 450 // order to reduce the number of tabs we need to check. If the tab at the
450 // estimated index is selected, check it first as it covers both tabs below 451 // estimated index is selected, check it first as it covers both tabs below
451 // it. Otherwise, check the tab to the left, then the estimated tab, and 452 // it. Otherwise, check the tab to the left, then the estimated tab, and
452 // finally the tab to the right (tabs stack to the left.) 453 // finally the tab to the right (tabs stack to the left.)
453 454
454 if (tabstrip->model()->selected_index() == index && 455 if (tabstrip->model()->selected_index() == index &&
455 tabstrip->GetTabAt(index)->IsPointInBounds(coord)) { 456 tabstrip->GetTabAt(index)->IsPointInBounds(coord)) {
456 tabstrip->hover_index_ = index; 457 tabstrip->hover_index_ = index;
457 } else if (index > 0 && 458 } else if (index > 0 &&
458 tabstrip->GetTabAt(index - 1)->IsPointInBounds(coord)) { 459 tabstrip->GetTabAt(index - 1)->IsPointInBounds(coord)) {
459 tabstrip->hover_index_ = index - 1; 460 tabstrip->hover_index_ = index - 1;
460 } else if (tabstrip->model()->selected_index() != index && 461 } else if (tabstrip->model()->selected_index() != index &&
461 tabstrip->GetTabAt(index)->IsPointInBounds(coord)) { 462 tabstrip->GetTabAt(index)->IsPointInBounds(coord)) {
462 tabstrip->hover_index_ = index; 463 tabstrip->hover_index_ = index;
463 } else if (index < tabstrip->model_->count() - 1 && 464 } else if (index < tab_count - 1 &&
464 tabstrip->GetTabAt(index + 1)->IsPointInBounds(coord)) { 465 tabstrip->GetTabAt(index + 1)->IsPointInBounds(coord)) {
465 tabstrip->hover_index_ = index + 1; 466 tabstrip->hover_index_ = index + 1;
466 } 467 }
467 468
468 // Nothing to do if the indexes are the same. 469 // Nothing to do if the indexes are the same.
469 if (tabstrip->hover_index_ != old_hover_index) { 470 if (tabstrip->hover_index_ != old_hover_index) {
470 if (tabstrip->hover_index_ != -1) 471 if (tabstrip->hover_index_ != -1)
471 tabstrip->GetTabAt(tabstrip->hover_index_)->SetHovering(true); 472 tabstrip->GetTabAt(tabstrip->hover_index_)->SetHovering(true);
472 473
473 if (old_hover_index != -1) 474 if (old_hover_index != -1 && old_hover_index < tab_count)
474 tabstrip->GetTabAt(old_hover_index)->SetHovering(false); 475 tabstrip->GetTabAt(old_hover_index)->SetHovering(false);
475 476
476 gtk_widget_queue_draw(tabstrip->tabstrip_.get()); 477 gtk_widget_queue_draw(tabstrip->tabstrip_.get());
477 } 478 }
478 479
479 return TRUE; 480 return TRUE;
480 } 481 }
481 482
482 // static 483 // static
483 gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event, 484 gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event,
(...skipping 13 matching lines...) Expand all
497 // GDK_CROSSING_GRAB. Ignore this event because it doesn't meant the mouse 498 // GDK_CROSSING_GRAB. Ignore this event because it doesn't meant the mouse
498 // has left the tabstrip. 499 // has left the tabstrip.
499 if (tabstrip->hover_index_ != -1 && event->mode != GDK_CROSSING_GRAB) { 500 if (tabstrip->hover_index_ != -1 && event->mode != GDK_CROSSING_GRAB) {
500 tabstrip->GetTabAt(tabstrip->hover_index_)->SetHovering(false); 501 tabstrip->GetTabAt(tabstrip->hover_index_)->SetHovering(false);
501 tabstrip->hover_index_ = -1; 502 tabstrip->hover_index_ = -1;
502 gtk_widget_queue_draw(tabstrip->tabstrip_.get()); 503 gtk_widget_queue_draw(tabstrip->tabstrip_.get());
503 } 504 }
504 505
505 return TRUE; 506 return TRUE;
506 } 507 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698