OLD | NEW |
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/views/extensions/extension_shelf.h" | 5 #include "chrome/browser/views/extensions/extension_shelf.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void DetachFromShelf(bool browser); | 146 void DetachFromShelf(bool browser); |
147 void AttachToShelf(bool browser); | 147 void AttachToShelf(bool browser); |
148 | 148 |
149 // Show / Hide the shelf handle. | 149 // Show / Hide the shelf handle. |
150 void ShowShelfHandle(); | 150 void ShowShelfHandle(); |
151 void DoShowShelfHandle(); | 151 void DoShowShelfHandle(); |
152 void HideShelfHandle(int delay_ms); | 152 void HideShelfHandle(int delay_ms); |
153 void DoHideShelfHandle(); | 153 void DoHideShelfHandle(); |
154 void StopHandleTimer(); | 154 void StopHandleTimer(); |
155 | 155 |
156 // Expand / Collapse | |
157 void Expand(int height, const GURL& url); | |
158 void Collapse(const GURL& url); | |
159 | |
160 // BrowserBubble::Delegate | 156 // BrowserBubble::Delegate |
161 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); | 157 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); |
162 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); | 158 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble); |
163 | 159 |
164 private: | 160 private: |
165 // The actual renderer that this toolstrip contains. | 161 // The actual renderer that this toolstrip contains. |
166 ExtensionHost* host_; | 162 ExtensionHost* host_; |
167 | 163 |
168 // Manifest definition of this toolstrip. | 164 // Manifest definition of this toolstrip. |
169 Extension::ToolstripInfo info_; | 165 Extension::ToolstripInfo info_; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 247 |
252 if (dragging_) { | 248 if (dragging_) { |
253 // when we're dragging, draw the bottom border. | 249 // when we're dragging, draw the bottom border. |
254 canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1); | 250 canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1); |
255 } | 251 } |
256 } | 252 } |
257 | 253 |
258 gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { | 254 gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { |
259 gfx::Size sz = title_->GetPreferredSize(); | 255 gfx::Size sz = title_->GetPreferredSize(); |
260 sz.set_width(std::max(view()->width(), sz.width())); | 256 sz.set_width(std::max(view()->width(), sz.width())); |
261 if (!expanded_) | 257 if (!expanded_) { |
262 sz.Enlarge(2 + kHandlePadding * 2, kHandlePadding * 2); | 258 sz.Enlarge(2 + kHandlePadding * 2, kHandlePadding * 2); |
| 259 } |
263 if (dragging_ || expanded_) { | 260 if (dragging_ || expanded_) { |
264 gfx::Size extension_size = view()->GetPreferredSize(); | 261 gfx::Size extension_size = view()->GetPreferredSize(); |
265 sz.Enlarge(0, extension_size.height() + 2); | 262 sz.Enlarge(0, extension_size.height() + 2); |
266 } | 263 } |
267 return sz; | 264 return sz; |
268 } | 265 } |
269 | 266 |
270 void ExtensionShelf::Toolstrip::Layout() { | 267 void ExtensionShelf::Toolstrip::Layout() { |
271 if (dragging_ || expanded_) { | 268 if (dragging_ || expanded_) { |
272 int y = title_->bounds().bottom() + kHandlePadding + 1; | 269 int y = title_->bounds().bottom() + kHandlePadding + 1; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Drop the toolstrip roughly where it is now. | 326 // Drop the toolstrip roughly where it is now. |
330 views::View::OnMouseReleased(event, canceled); | 327 views::View::OnMouseReleased(event, canceled); |
331 dragging_ = false; | 328 dragging_ = false; |
332 // |this| and |shelf_| are in different view hierarchies, so we need to | 329 // |this| and |shelf_| are in different view hierarchies, so we need to |
333 // convert to screen coordinates and back again to map locations. | 330 // convert to screen coordinates and back again to map locations. |
334 gfx::Point loc = event.location(); | 331 gfx::Point loc = event.location(); |
335 View::ConvertPointToScreen(this, &loc); | 332 View::ConvertPointToScreen(this, &loc); |
336 View::ConvertPointToView(NULL, shelf_, &loc); | 333 View::ConvertPointToView(NULL, shelf_, &loc); |
337 shelf_->DropExtension(this, loc, canceled); | 334 shelf_->DropExtension(this, loc, canceled); |
338 AttachToShelf(true); | 335 AttachToShelf(true); |
339 } else if (!canceled) { | 336 } else if (!canceled && |
| 337 info_.mole.is_valid() && info_.toolstrip.is_valid()) { |
340 // Toggle mole to either expanded or collapsed. | 338 // Toggle mole to either expanded or collapsed. |
341 // TODO(erikkay) If there's no valid URL in the manifest, should we | 339 expanded_ = !expanded_; |
342 // post an event to the toolstrip in this case? | 340 view()->set_is_toolstrip(!expanded_); |
343 if (expanded_) { | 341 if (expanded_) { |
344 if (info_.toolstrip.is_valid()) | 342 host_->NavigateToURL(info_.mole); |
345 shelf_->CollapseToolstrip(host_, info_.toolstrip); | 343 StopHandleTimer(); |
| 344 DetachFromShelf(false); |
| 345 |
| 346 gfx::Size extension_size = view()->GetPreferredSize(); |
| 347 extension_size.set_height(info_.mole_height); |
| 348 view()->SetPreferredSize(extension_size); |
| 349 LayoutHandle(); |
346 } else { | 350 } else { |
347 if (info_.mole.is_valid()) | 351 gfx::Size extension_size = view()->GetPreferredSize(); |
348 shelf_->ExpandToolstrip(host_, info_.mole, info_.mole_height); | 352 extension_size.set_height(kToolstripHeight); |
| 353 view()->SetPreferredSize(extension_size); |
| 354 |
| 355 host_->NavigateToURL(info_.toolstrip); |
| 356 AttachToShelf(false); |
349 } | 357 } |
| 358 |
| 359 // This is to prevent flickering as the page loads and lays out. |
| 360 // Once the navigation is finished, ExtensionView will wind up setting |
| 361 // visibility to true. |
| 362 view()->SetVisible(false); |
350 } | 363 } |
351 } | 364 } |
352 | 365 |
353 BrowserBubble* ExtensionShelf::Toolstrip::GetHandle() { | 366 BrowserBubble* ExtensionShelf::Toolstrip::GetHandle() { |
354 if (!handle_.get()) { | 367 if (!handle_.get()) { |
355 handle_.reset(new BrowserBubble(this, shelf_->GetWidget(), | 368 handle_.reset(new BrowserBubble(this, shelf_->GetWidget(), |
356 gfx::Point(0, 0))); | 369 gfx::Point(0, 0))); |
357 handle_->set_delegate(this); | 370 handle_->set_delegate(this); |
358 LayoutHandle(); | 371 LayoutHandle(); |
359 } | 372 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 BrowserBubble* bubble) { | 407 BrowserBubble* bubble) { |
395 HideShelfHandle(0); | 408 HideShelfHandle(0); |
396 } | 409 } |
397 | 410 |
398 void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing( | 411 void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing( |
399 BrowserBubble* bubble) { | 412 BrowserBubble* bubble) { |
400 DoHideShelfHandle(); | 413 DoHideShelfHandle(); |
401 } | 414 } |
402 | 415 |
403 void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { | 416 void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { |
404 DCHECK(handle_.get()); | |
405 DCHECK(!placeholder_view_); | 417 DCHECK(!placeholder_view_); |
406 if (browserDetach && handle_->attached()) | 418 if (browserDetach && handle_->attached()) |
407 handle_->DetachFromBrowser(); | 419 handle_->DetachFromBrowser(); |
408 | 420 |
409 // Construct a placeholder view to replace the view. | 421 // Construct a placeholder view to replace the view. |
410 placeholder_view_ = new PlaceholderView(); | 422 placeholder_view_ = new PlaceholderView(); |
411 placeholder_view_->SetBounds(view()->bounds()); | 423 placeholder_view_->SetBounds(view()->bounds()); |
412 shelf_->AddChildView(placeholder_view_); | 424 shelf_->AddChildView(placeholder_view_); |
413 | 425 |
414 AddChildView(view()); | 426 AddChildView(view()); |
415 SizeToPreferredSize(); | 427 SizeToPreferredSize(); |
416 handle_->ResizeToView(); | 428 handle_->ResizeToView(); |
417 Layout(); | 429 Layout(); |
418 } | 430 } |
419 | 431 |
420 void ExtensionShelf::Toolstrip::AttachToShelf(bool browserAttach) { | 432 void ExtensionShelf::Toolstrip::AttachToShelf(bool browserAttach) { |
421 DCHECK(handle_.get()); | |
422 DCHECK(placeholder_view_); | |
423 if (browserAttach && !handle_->attached()) | 433 if (browserAttach && !handle_->attached()) |
424 handle_->AttachToBrowser(); | 434 handle_->AttachToBrowser(); |
425 | 435 |
426 // Move the view back into the shelf and remove the old placeholder. | 436 // Move the view back into the shelf and remove the old placeholder. |
427 shelf_->AddChildView(view()); | 437 shelf_->AddChildView(view()); |
428 | 438 |
429 // The size of the view may have changed, so just set the position. | 439 // The size of the view may have changed, so just set the position. |
430 view()->SetX(placeholder_view_->x()); | 440 view()->SetX(placeholder_view_->x()); |
431 view()->SetY(placeholder_view_->y()); | 441 view()->SetY(placeholder_view_->y()); |
432 | 442 |
(...skipping 23 matching lines...) Expand all Loading... |
456 handle_->DetachFromBrowser(); | 466 handle_->DetachFromBrowser(); |
457 handle_.reset(NULL); | 467 handle_.reset(NULL); |
458 shelf_->Layout(); | 468 shelf_->Layout(); |
459 } | 469 } |
460 | 470 |
461 void ExtensionShelf::Toolstrip::StopHandleTimer() { | 471 void ExtensionShelf::Toolstrip::StopHandleTimer() { |
462 if (!timer_factory_.empty()) | 472 if (!timer_factory_.empty()) |
463 timer_factory_.RevokeAll(); | 473 timer_factory_.RevokeAll(); |
464 } | 474 } |
465 | 475 |
466 void ExtensionShelf::Toolstrip::Expand(int height, const GURL& url) { | |
467 DCHECK(!expanded_); | |
468 | |
469 DoShowShelfHandle(); | |
470 | |
471 expanded_ = true; | |
472 view()->set_is_toolstrip(!expanded_); | |
473 | |
474 bool navigate = (!url.is_empty() && url != host_->GetURL()); | |
475 if (navigate) | |
476 host_->NavigateToURL(url); | |
477 | |
478 StopHandleTimer(); | |
479 DetachFromShelf(false); | |
480 | |
481 gfx::Size extension_size = view()->GetPreferredSize(); | |
482 extension_size.set_height(height); | |
483 view()->SetPreferredSize(extension_size); | |
484 LayoutHandle(); | |
485 | |
486 // This is to prevent flickering as the page loads and lays out. | |
487 // Once the navigation is finished, ExtensionView will wind up setting | |
488 // visibility to true. | |
489 if (navigate) | |
490 view()->SetVisible(false); | |
491 } | |
492 | |
493 void ExtensionShelf::Toolstrip::Collapse(const GURL& url) { | |
494 DCHECK(expanded_); | |
495 expanded_ = false; | |
496 view()->set_is_toolstrip(!expanded_); | |
497 | |
498 gfx::Size extension_size = view()->GetPreferredSize(); | |
499 extension_size.set_height(kToolstripHeight); | |
500 view()->SetPreferredSize(extension_size); | |
501 AttachToShelf(false); | |
502 | |
503 if (!url.is_empty() && url != host_->GetURL()) { | |
504 host_->NavigateToURL(url); | |
505 | |
506 // This is to prevent flickering as the page loads and lays out. | |
507 // Once the navigation is finished, ExtensionView will wind up setting | |
508 // visibility to true. | |
509 view()->SetVisible(false); | |
510 } | |
511 | |
512 // Must use the delay due to bug 18248. | |
513 HideShelfHandle(kHideDelayMs); | |
514 } | |
515 | |
516 void ExtensionShelf::Toolstrip::ShowShelfHandle() { | 476 void ExtensionShelf::Toolstrip::ShowShelfHandle() { |
517 StopHandleTimer(); | 477 StopHandleTimer(); |
518 if (handle_visible()) | 478 if (handle_visible()) |
519 return; | 479 return; |
520 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 480 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
521 timer_factory_.NewRunnableMethod( | 481 timer_factory_.NewRunnableMethod( |
522 &ExtensionShelf::Toolstrip::DoShowShelfHandle), | 482 &ExtensionShelf::Toolstrip::DoShowShelfHandle), |
523 1000); | 483 1000); |
524 } | 484 } |
525 | 485 |
526 void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { | 486 void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { |
527 StopHandleTimer(); | 487 StopHandleTimer(); |
528 if (!handle_visible() || dragging_ || expanded_) | 488 if (!handle_visible() || dragging_ || expanded_) |
529 return; | 489 return; |
530 if (delay_ms) { | 490 if (delay_ms) { |
531 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 491 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
532 timer_factory_.NewRunnableMethod( | 492 timer_factory_.NewRunnableMethod( |
533 &ExtensionShelf::Toolstrip::DoHideShelfHandle), | 493 &ExtensionShelf::Toolstrip::DoHideShelfHandle), |
534 delay_ms); | 494 delay_ms); |
535 } else { | 495 } else { |
536 DoHideShelfHandle(); | 496 DoHideShelfHandle(); |
537 } | 497 } |
538 } | 498 } |
539 | 499 |
540 //////////////////////////////////////////////////////////////////////////////// | 500 //////////////////////////////////////////////////////////////////////////////// |
541 | 501 |
542 ExtensionShelf::ExtensionShelf(Browser* browser) | 502 ExtensionShelf::ExtensionShelf(Browser* browser) |
543 : model_(browser->extension_shelf_model()) { | 503 : model_(new ExtensionShelfModel(browser)) { |
544 model_->AddObserver(this); | 504 model_->AddObserver(this); |
545 LoadFromModel(); | 505 LoadFromModel(); |
546 EnableCanvasFlippingForRTLUI(true); | 506 EnableCanvasFlippingForRTLUI(true); |
547 } | 507 } |
548 | 508 |
549 ExtensionShelf::~ExtensionShelf() { | 509 ExtensionShelf::~ExtensionShelf() { |
550 if (model_) { | 510 int count = model_->count(); |
551 int count = model_->count(); | 511 for (int i = 0; i < count; ++i) { |
552 for (int i = 0; i < count; ++i) { | 512 delete ToolstripAtIndex(i); |
553 delete ToolstripAtIndex(i); | 513 model_->SetToolstripDataAt(i, NULL); |
554 model_->SetToolstripDataAt(i, NULL); | |
555 } | |
556 model_->RemoveObserver(this); | |
557 } | 514 } |
| 515 model_->RemoveObserver(this); |
558 } | 516 } |
559 | 517 |
560 void ExtensionShelf::Paint(gfx::Canvas* canvas) { | 518 void ExtensionShelf::Paint(gfx::Canvas* canvas) { |
561 #if 0 | 519 #if 0 |
562 // TODO(erikkay) re-enable this when Glen has the gradient values worked out. | 520 // TODO(erikkay) re-enable this when Glen has the gradient values worked out. |
563 SkPaint paint; | 521 SkPaint paint; |
564 paint.setShader(skia::CreateGradientShader(0, | 522 paint.setShader(skia::CreateGradientShader(0, |
565 height(), | 523 height(), |
566 kTopGradientColor, | 524 kTopGradientColor, |
567 kBackgroundColor))->safeUnref(); | 525 kBackgroundColor))->safeUnref(); |
(...skipping 30 matching lines...) Expand all Loading... |
598 void ExtensionShelf::ChildPreferredSizeChanged(View* child) { | 556 void ExtensionShelf::ChildPreferredSizeChanged(View* child) { |
599 Toolstrip *toolstrip = ToolstripForView(static_cast<ExtensionView*>(child)); | 557 Toolstrip *toolstrip = ToolstripForView(static_cast<ExtensionView*>(child)); |
600 if (!toolstrip) | 558 if (!toolstrip) |
601 return; | 559 return; |
602 Layout(); | 560 Layout(); |
603 } | 561 } |
604 | 562 |
605 void ExtensionShelf::Layout() { | 563 void ExtensionShelf::Layout() { |
606 if (!GetParent()) | 564 if (!GetParent()) |
607 return; | 565 return; |
608 if (!model_) | |
609 return; | |
610 | 566 |
611 int x = kLeftMargin; | 567 int x = kLeftMargin; |
612 int y = kTopMargin; | 568 int y = kTopMargin; |
613 int content_height = height() - kTopMargin - kBottomMargin; | 569 int content_height = height() - kTopMargin - kBottomMargin; |
614 int max_x = width() - kRightMargin; | 570 int max_x = width() - kRightMargin; |
615 | 571 |
616 int count = model_->count(); | 572 int count = model_->count(); |
617 for (int i = 0; i < count; ++i) { | 573 for (int i = 0; i < count; ++i) { |
618 x += kToolstripPadding; // left padding | 574 x += kToolstripPadding; // left padding |
619 Toolstrip* toolstrip = ToolstripAtIndex(i); | 575 Toolstrip* toolstrip = ToolstripAtIndex(i); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 return false; | 612 return false; |
657 } | 613 } |
658 | 614 |
659 void ExtensionShelf::SetAccessibleName(const std::wstring& name) { | 615 void ExtensionShelf::SetAccessibleName(const std::wstring& name) { |
660 accessible_name_.assign(name); | 616 accessible_name_.assign(name); |
661 } | 617 } |
662 | 618 |
663 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, | 619 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, |
664 int index) { | 620 int index) { |
665 model_->SetToolstripDataAt(index, | 621 model_->SetToolstripDataAt(index, |
666 new Toolstrip(this, host, model_->ToolstripAt(index).info)); | 622 new Toolstrip(this, host, model_->ToolstripInfoAt(index))); |
667 | 623 |
668 bool had_views = GetChildViewCount() > 0; | 624 bool had_views = GetChildViewCount() > 0; |
669 ExtensionView* view = host->view(); | 625 ExtensionView* view = host->view(); |
670 if (!background_.empty()) | 626 if (!background_.empty()) |
671 view->SetBackground(background_); | 627 view->SetBackground(background_); |
672 AddChildView(view); | 628 AddChildView(view); |
673 view->SetContainer(this); | 629 view->SetContainer(this); |
674 if (!had_views) | 630 if (!had_views) |
675 PreferredSizeChanged(); | 631 PreferredSizeChanged(); |
676 Layout(); | 632 Layout(); |
(...skipping 13 matching lines...) Expand all Loading... |
690 } | 646 } |
691 | 647 |
692 void ExtensionShelf::ToolstripDraggingFrom(ExtensionHost* host, int index) { | 648 void ExtensionShelf::ToolstripDraggingFrom(ExtensionHost* host, int index) { |
693 } | 649 } |
694 | 650 |
695 void ExtensionShelf::ToolstripMoved(ExtensionHost* host, int from_index, | 651 void ExtensionShelf::ToolstripMoved(ExtensionHost* host, int from_index, |
696 int to_index) { | 652 int to_index) { |
697 Layout(); | 653 Layout(); |
698 } | 654 } |
699 | 655 |
700 void ExtensionShelf::ToolstripChanged(ExtensionShelfModel::iterator toolstrip) { | 656 void ExtensionShelf::ToolstripChangedAt(ExtensionHost* toolstrip, int index) { |
701 Toolstrip* t = static_cast<Toolstrip*>(toolstrip->data); | |
702 if (toolstrip->height > 0) { | |
703 if (!t->expanded()) { | |
704 t->Expand(toolstrip->height, toolstrip->url); | |
705 } | |
706 } else if (t->expanded()) { | |
707 t->Collapse(toolstrip->url); | |
708 } | |
709 } | 657 } |
710 | 658 |
711 void ExtensionShelf::ExtensionShelfEmpty() { | 659 void ExtensionShelf::ExtensionShelfEmpty() { |
712 PreferredSizeChanged(); | 660 PreferredSizeChanged(); |
713 } | 661 } |
714 | 662 |
715 void ExtensionShelf::ShelfModelReloaded() { | 663 void ExtensionShelf::ShelfModelReloaded() { |
716 // None of the child views are parent owned, so nothing is being leaked here. | 664 // None of the child views are parent owned, so nothing is being leaked here. |
717 RemoveAllChildViews(false); | 665 RemoveAllChildViews(false); |
718 LoadFromModel(); | 666 LoadFromModel(); |
719 } | 667 } |
720 | 668 |
721 void ExtensionShelf::ShelfModelDeleting() { | |
722 int count = model_->count(); | |
723 for (int i = 0; i < count; ++i) { | |
724 delete ToolstripAtIndex(i); | |
725 model_->SetToolstripDataAt(i, NULL); | |
726 } | |
727 model_->RemoveObserver(this); | |
728 model_ = NULL; | |
729 } | |
730 | |
731 void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { | 669 void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { |
732 Toolstrip *toolstrip = ToolstripForView(view); | 670 Toolstrip *toolstrip = ToolstripForView(view); |
733 if (toolstrip) | 671 if (toolstrip) |
734 toolstrip->ShowShelfHandle(); | 672 toolstrip->ShowShelfHandle(); |
735 } | 673 } |
736 | 674 |
737 void ExtensionShelf::OnExtensionMouseLeave(ExtensionView* view) { | 675 void ExtensionShelf::OnExtensionMouseLeave(ExtensionView* view) { |
738 Toolstrip *toolstrip = ToolstripForView(view); | 676 Toolstrip *toolstrip = ToolstripForView(view); |
739 if (toolstrip) | 677 if (toolstrip) |
740 toolstrip->HideShelfHandle(kHideDelayMs); | 678 toolstrip->HideShelfHandle(kHideDelayMs); |
741 } | 679 } |
742 | 680 |
743 void ExtensionShelf::DropExtension(Toolstrip* toolstrip, const gfx::Point& pt, | 681 void ExtensionShelf::DropExtension(Toolstrip* toolstrip, const gfx::Point& pt, |
744 bool cancel) { | 682 bool cancel) { |
745 Toolstrip* dest_toolstrip = ToolstripAtX(pt.x()); | 683 Toolstrip* dest_toolstrip = ToolstripAtX(pt.x()); |
746 if (!dest_toolstrip) { | 684 if (!dest_toolstrip) { |
747 if (pt.x() > 0) | 685 if (pt.x() > 0) |
748 dest_toolstrip = ToolstripAtIndex(model_->count() - 1); | 686 dest_toolstrip = ToolstripAtIndex(model_->count() - 1); |
749 else | 687 else |
750 dest_toolstrip = ToolstripAtIndex(0); | 688 dest_toolstrip = ToolstripAtIndex(0); |
751 } | 689 } |
752 if (toolstrip == dest_toolstrip) | 690 if (toolstrip == dest_toolstrip) |
753 return; | 691 return; |
754 int from = model_->IndexOfHost(toolstrip->host()); | 692 int from = model_->IndexOfToolstrip(toolstrip->host()); |
755 int to = model_->IndexOfHost(dest_toolstrip->host()); | 693 int to = model_->IndexOfToolstrip(dest_toolstrip->host()); |
756 DCHECK(from != to); | 694 DCHECK(from != to); |
757 model_->MoveToolstripAt(from, to); | 695 model_->MoveToolstripAt(from, to); |
758 } | 696 } |
759 | 697 |
760 void ExtensionShelf::ExpandToolstrip(ExtensionHost* host, const GURL& url, | |
761 int height) { | |
762 ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); | |
763 model_->ExpandToolstrip(toolstrip, url, height); | |
764 } | |
765 | |
766 void ExtensionShelf::CollapseToolstrip(ExtensionHost* host, const GURL& url) { | |
767 ExtensionShelfModel::iterator toolstrip = model_->ToolstripForHost(host); | |
768 model_->CollapseToolstrip(toolstrip, url); | |
769 } | |
770 | |
771 void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) { | 698 void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) { |
772 if (!background_.empty()) | 699 if (!background_.empty()) |
773 return; | 700 return; |
774 | 701 |
775 const SkBitmap& background = canvas->getDevice()->accessBitmap(false); | 702 const SkBitmap& background = canvas->getDevice()->accessBitmap(false); |
776 | 703 |
777 // Extract the correct subset of the toolstrip background into a bitmap. We | 704 // Extract the correct subset of the toolstrip background into a bitmap. We |
778 // must use a temporary here because extractSubset() returns a bitmap that | 705 // must use a temporary here because extractSubset() returns a bitmap that |
779 // references pixels in the original one and we want to actually make a copy | 706 // references pixels in the original one and we want to actually make a copy |
780 // that will have a long lifetime. | 707 // that will have a long lifetime. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 View* view = toolstrip->GetShelfView(); | 742 View* view = toolstrip->GetShelfView(); |
816 if (x > (view->x() + view->width() + kToolstripPadding)) | 743 if (x > (view->x() + view->width() + kToolstripPadding)) |
817 continue; | 744 continue; |
818 return toolstrip; | 745 return toolstrip; |
819 } | 746 } |
820 | 747 |
821 return NULL; | 748 return NULL; |
822 } | 749 } |
823 | 750 |
824 ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtIndex(int index) { | 751 ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripAtIndex(int index) { |
825 return static_cast<Toolstrip*>(model_->ToolstripAt(index).data); | 752 return static_cast<Toolstrip*>(model_->ToolstripDataAt(index)); |
826 } | 753 } |
827 | 754 |
828 ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( | 755 ExtensionShelf::Toolstrip* ExtensionShelf::ToolstripForView( |
829 ExtensionView* view) { | 756 ExtensionView* view) { |
830 int count = model_->count(); | 757 int count = model_->count(); |
831 for (int i = 0; i < count; ++i) { | 758 for (int i = 0; i < count; ++i) { |
832 Toolstrip* toolstrip = ToolstripAtIndex(i); | 759 Toolstrip* toolstrip = ToolstripAtIndex(i); |
833 if (view == toolstrip->view()) | 760 if (view == toolstrip->view()) |
834 return toolstrip; | 761 return toolstrip; |
835 } | 762 } |
| 763 NOTREACHED(); |
836 return NULL; | 764 return NULL; |
837 } | 765 } |
838 | 766 |
839 void ExtensionShelf::LoadFromModel() { | 767 void ExtensionShelf::LoadFromModel() { |
840 int count = model_->count(); | 768 int count = model_->count(); |
841 for (int i = 0; i < count; ++i) | 769 for (int i = 0; i < count; ++i) |
842 ToolstripInsertedAt(model_->ToolstripAt(i).host, i); | 770 ToolstripInsertedAt(model_->ToolstripAt(i), i); |
843 } | 771 } |
OLD | NEW |