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

Side by Side Diff: chrome/browser/views/extensions/extension_shelf.cc

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

Powered by Google App Engine
This is Rietveld 408576698