Chromium Code Reviews| 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 } | 558 } |
| 559 SchedulePaint(); | 559 SchedulePaint(); |
| 560 } | 560 } |
| 561 | 561 |
| 562 void ExtensionShelf::OnMouseEntered(const views::MouseEvent& event) { | 562 void ExtensionShelf::OnMouseEntered(const views::MouseEvent& event) { |
| 563 } | 563 } |
| 564 | 564 |
| 565 void ExtensionShelf::OnMouseExited(const views::MouseEvent& event) { | 565 void ExtensionShelf::OnMouseExited(const views::MouseEvent& event) { |
| 566 } | 566 } |
| 567 | 567 |
| 568 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, | 568 bool ExtensionShelf::GetAccessibleRole(AccessibilityTypes::Role* role) { |
| 569 int index) { | 569 DCHECK(role); |
| 570 | |
| 571 *role = AccessibilityTypes::ROLE_TOOLBAR; | |
| 572 return true; | |
| 573 } | |
| 574 | |
| 575 bool ExtensionShelf::GetAccessibleName(std::wstring* name) { | |
| 576 if (!accessible_name_.empty()) { | |
|
jcampan
2009/07/14 16:44:24
Same nit as previously: DCHECK(name), name->assign
| |
| 577 (*name).assign(accessible_name_); | |
| 578 return true; | |
| 579 } | |
| 580 return false; | |
| 581 } | |
| 582 | |
| 583 void ExtensionShelf::SetAccessibleName(const std::wstring& name) { | |
| 584 accessible_name_.assign(name); | |
| 585 } | |
| 586 | |
| 587 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) { | |
| 570 model_->SetToolstripDataAt(index, new Toolstrip(this, host)); | 588 model_->SetToolstripDataAt(index, new Toolstrip(this, host)); |
| 571 | 589 |
| 572 bool had_views = GetChildViewCount() > 0; | 590 bool had_views = GetChildViewCount() > 0; |
| 573 ExtensionView* view = host->view(); | 591 ExtensionView* view = host->view(); |
| 574 if (!background_.empty()) | 592 if (!background_.empty()) |
| 575 view->SetBackground(background_); | 593 view->SetBackground(background_); |
| 576 AddChildView(view); | 594 AddChildView(view); |
| 577 view->SetContainer(this); | 595 view->SetContainer(this); |
| 578 if (!had_views) | 596 if (!had_views) |
| 579 PreferredSizeChanged(); | 597 PreferredSizeChanged(); |
| 580 Layout(); | 598 Layout(); |
| 581 } | 599 } |
| 582 | 600 |
| 583 void ExtensionShelf::ToolstripRemovingAt(ExtensionHost* host, | 601 void ExtensionShelf::ToolstripRemovingAt(ExtensionHost* host, int index) { |
| 584 int index) { | |
| 585 // Delete the Toolstrip view and remove it from the model. | 602 // Delete the Toolstrip view and remove it from the model. |
| 586 Toolstrip* toolstrip = ToolstripAtIndex(index); | 603 Toolstrip* toolstrip = ToolstripAtIndex(index); |
| 587 View* view = toolstrip->GetShelfView(); | 604 View* view = toolstrip->GetShelfView(); |
| 588 RemoveChildView(view); | 605 RemoveChildView(view); |
| 589 delete toolstrip; | 606 delete toolstrip; |
| 590 model_->SetToolstripDataAt(index, NULL); | 607 model_->SetToolstripDataAt(index, NULL); |
| 591 | 608 |
| 592 // Technically, the toolstrip is still in the model at this point, but | 609 // Technically, the toolstrip is still in the model at this point, but |
| 593 // the Layout code handles this case. | 610 // the Layout code handles this case. |
| 594 Layout(); | 611 Layout(); |
| 595 } | 612 } |
| 596 | 613 |
| 597 void ExtensionShelf::ToolstripDraggingFrom(ExtensionHost* host, | 614 void ExtensionShelf::ToolstripDraggingFrom(ExtensionHost* host, int index) { |
| 598 int index) { | |
| 599 } | 615 } |
| 600 | 616 |
| 601 void ExtensionShelf::ToolstripMoved(ExtensionHost* host, | 617 void ExtensionShelf::ToolstripMoved(ExtensionHost* host, int from_index, |
| 602 int from_index, | |
| 603 int to_index) { | 618 int to_index) { |
| 604 Layout(); | 619 Layout(); |
| 605 } | 620 } |
| 606 | 621 |
| 607 void ExtensionShelf::ToolstripChangedAt(ExtensionHost* toolstrip, | 622 void ExtensionShelf::ToolstripChangedAt(ExtensionHost* toolstrip, int index) { |
| 608 int index) { | |
| 609 } | 623 } |
| 610 | 624 |
| 611 void ExtensionShelf::ExtensionShelfEmpty() { | 625 void ExtensionShelf::ExtensionShelfEmpty() { |
| 612 PreferredSizeChanged(); | 626 PreferredSizeChanged(); |
| 613 } | 627 } |
| 614 | 628 |
| 615 void ExtensionShelf::ShelfModelReloaded() { | 629 void ExtensionShelf::ShelfModelReloaded() { |
| 616 // None of the child views are parent owned, so nothing is being leaked here. | 630 // None of the child views are parent owned, so nothing is being leaked here. |
| 617 RemoveAllChildViews(false); | 631 RemoveAllChildViews(false); |
| 618 LoadFromModel(); | 632 LoadFromModel(); |
| 619 } | 633 } |
| 620 | 634 |
| 621 void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { | 635 void ExtensionShelf::OnExtensionMouseEvent(ExtensionView* view) { |
| 622 Toolstrip *toolstrip = ToolstripForView(view); | 636 Toolstrip *toolstrip = ToolstripForView(view); |
| 623 if (toolstrip) | 637 if (toolstrip) |
| 624 toolstrip->ShowShelfHandle(); | 638 toolstrip->ShowShelfHandle(); |
| 625 } | 639 } |
| 626 | 640 |
| 627 void ExtensionShelf::OnExtensionMouseLeave(ExtensionView* view) { | 641 void ExtensionShelf::OnExtensionMouseLeave(ExtensionView* view) { |
| 628 Toolstrip *toolstrip = ToolstripForView(view); | 642 Toolstrip *toolstrip = ToolstripForView(view); |
| 629 if (toolstrip) | 643 if (toolstrip) |
| 630 toolstrip->HideShelfHandle(kHideDelayMs); | 644 toolstrip->HideShelfHandle(kHideDelayMs); |
| 631 } | 645 } |
| 632 | 646 |
| 633 void ExtensionShelf::DropExtension(Toolstrip* toolstrip, | 647 void ExtensionShelf::DropExtension(Toolstrip* toolstrip, const gfx::Point& pt, |
| 634 const gfx::Point& pt, bool cancel) { | 648 bool cancel) { |
| 635 Toolstrip* dest_toolstrip = ToolstripAtX(pt.x()); | 649 Toolstrip* dest_toolstrip = ToolstripAtX(pt.x()); |
| 636 if (!dest_toolstrip) { | 650 if (!dest_toolstrip) { |
| 637 if (pt.x() > 0) | 651 if (pt.x() > 0) |
| 638 dest_toolstrip = ToolstripAtIndex(model_->count() - 1); | 652 dest_toolstrip = ToolstripAtIndex(model_->count() - 1); |
| 639 else | 653 else |
| 640 dest_toolstrip = ToolstripAtIndex(0); | 654 dest_toolstrip = ToolstripAtIndex(0); |
| 641 } | 655 } |
| 642 if (toolstrip == dest_toolstrip) | 656 if (toolstrip == dest_toolstrip) |
| 643 return; | 657 return; |
| 644 int from = model_->IndexOfToolstrip(toolstrip->host()); | 658 int from = model_->IndexOfToolstrip(toolstrip->host()); |
| 645 int to = model_->IndexOfToolstrip(dest_toolstrip->host()); | 659 int to = model_->IndexOfToolstrip(dest_toolstrip->host()); |
| 646 DCHECK(from != to); | 660 DCHECK(from != to); |
| 647 model_->MoveToolstripAt(from, to); | 661 model_->MoveToolstripAt(from, to); |
| 648 } | 662 } |
| 649 | 663 |
| 650 void ExtensionShelf::InitBackground(gfx::Canvas* canvas, | 664 void ExtensionShelf::InitBackground(gfx::Canvas* canvas, const SkRect& subset) { |
| 651 const SkRect& subset) { | |
| 652 if (!background_.empty()) | 665 if (!background_.empty()) |
| 653 return; | 666 return; |
| 654 | 667 |
| 655 const SkBitmap& background = canvas->getDevice()->accessBitmap(false); | 668 const SkBitmap& background = canvas->getDevice()->accessBitmap(false); |
| 656 | 669 |
| 657 // Extract the correct subset of the toolstrip background into a bitmap. We | 670 // Extract the correct subset of the toolstrip background into a bitmap. We |
| 658 // must use a temporary here because extractSubset() returns a bitmap that | 671 // must use a temporary here because extractSubset() returns a bitmap that |
| 659 // references pixels in the original one and we want to actually make a copy | 672 // references pixels in the original one and we want to actually make a copy |
| 660 // that will have a long lifetime. | 673 // that will have a long lifetime. |
| 661 SkBitmap temp; | 674 SkBitmap temp; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 } | 728 } |
| 716 NOTREACHED(); | 729 NOTREACHED(); |
| 717 return NULL; | 730 return NULL; |
| 718 } | 731 } |
| 719 | 732 |
| 720 void ExtensionShelf::LoadFromModel() { | 733 void ExtensionShelf::LoadFromModel() { |
| 721 int count = model_->count(); | 734 int count = model_->count(); |
| 722 for (int i = 0; i < count; ++i) | 735 for (int i = 0; i < count; ++i) |
| 723 ToolstripInsertedAt(model_->ToolstripAt(i), i); | 736 ToolstripInsertedAt(model_->ToolstripAt(i), i); |
| 724 } | 737 } |
| OLD | NEW |