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

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

Issue 159202: add mole info to toolstrip definition and enable moles (Closed)
Patch Set: ready for review Created 11 years, 5 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 private: 79 private:
80 DISALLOW_COPY_AND_ASSIGN(PlaceholderView); 80 DISALLOW_COPY_AND_ASSIGN(PlaceholderView);
81 }; 81 };
82 82
83 // A wrapper class for the ExtensionHost displayed as a toolstrip. 83 // A wrapper class for the ExtensionHost displayed as a toolstrip.
84 // The class itself also acts as the View for the handle of the toolstrip 84 // The class itself also acts as the View for the handle of the toolstrip
85 // it represents. 85 // it represents.
86 class ExtensionShelf::Toolstrip : public views::View, 86 class ExtensionShelf::Toolstrip : public views::View,
87 public BrowserBubble::Delegate { 87 public BrowserBubble::Delegate {
88 public: 88 public:
89 Toolstrip(ExtensionShelf* shelf, ExtensionHost* host); 89 Toolstrip(ExtensionShelf* shelf, ExtensionHost* host,
90 Extension::ToolstripInfo* info);
90 virtual ~Toolstrip(); 91 virtual ~Toolstrip();
91 92
92 // View 93 // View
93 virtual void Paint(gfx::Canvas* canvas); 94 virtual void Paint(gfx::Canvas* canvas);
94 virtual gfx::Size GetPreferredSize(); 95 virtual gfx::Size GetPreferredSize();
95 virtual void Layout(); 96 virtual void Layout();
96 virtual void OnMouseEntered(const views::MouseEvent& event); 97 virtual void OnMouseEntered(const views::MouseEvent& event);
97 virtual void OnMouseExited(const views::MouseEvent& event); 98 virtual void OnMouseExited(const views::MouseEvent& event);
98 virtual bool OnMousePressed(const views::MouseEvent& event); 99 virtual bool OnMousePressed(const views::MouseEvent& event);
99 virtual bool OnMouseDragged(const views::MouseEvent& event); 100 virtual bool OnMouseDragged(const views::MouseEvent& event);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 140
140 // Show / Hide the shelf handle. 141 // Show / Hide the shelf handle.
141 void ShowShelfHandle(); 142 void ShowShelfHandle();
142 void DoShowShelfHandle(); 143 void DoShowShelfHandle();
143 void HideShelfHandle(int delay_ms); 144 void HideShelfHandle(int delay_ms);
144 void DoHideShelfHandle(); 145 void DoHideShelfHandle();
145 void StopHandleTimer(); 146 void StopHandleTimer();
146 147
147 // BrowserBubble::Delegate 148 // BrowserBubble::Delegate
148 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble); 149 virtual void BubbleBrowserWindowMoved(BrowserBubble* bubble);
149 virtual void BubbleBrowserWindowClosed(BrowserBubble* bubble); 150 virtual void BubbleBrowserWindowClosing(BrowserBubble* bubble);
150 151
151 private: 152 private:
152 // The actual renderer that this toolstrip contains. 153 // The actual renderer that this toolstrip contains.
153 ExtensionHost* host_; 154 ExtensionHost* host_;
154 155
156 // Manifest definition of this toolstrip.
157 Extension::ToolstripInfo* info_;
158
155 // The handle is a BrowserBubble so that it can exist as an independent, 159 // The handle is a BrowserBubble so that it can exist as an independent,
156 // floating window. It also acts as the container for the ExtensionView when 160 // floating window. It also acts as the container for the ExtensionView when
157 // it's being dragged. 161 // it's being dragged.
158 scoped_ptr<BrowserBubble> handle_; 162 scoped_ptr<BrowserBubble> handle_;
159 163
160 // Used for drawing the name of the extension in the handle. 164 // Used for drawing the name of the extension in the handle.
161 scoped_ptr<views::Label> title_; 165 scoped_ptr<views::Label> title_;
162 166
163 // Pointer back to the containing shelf. 167 // Pointer back to the containing shelf.
164 ExtensionShelf* shelf_; 168 ExtensionShelf* shelf_;
(...skipping 12 matching lines...) Expand all
177 // If dragging, where did the drag start from. 181 // If dragging, where did the drag start from.
178 gfx::Point initial_drag_location_; 182 gfx::Point initial_drag_location_;
179 183
180 // Timers for tracking mouse hovering. 184 // Timers for tracking mouse hovering.
181 ScopedRunnableMethodFactory<ExtensionShelf::Toolstrip> timer_factory_; 185 ScopedRunnableMethodFactory<ExtensionShelf::Toolstrip> timer_factory_;
182 186
183 DISALLOW_COPY_AND_ASSIGN(Toolstrip); 187 DISALLOW_COPY_AND_ASSIGN(Toolstrip);
184 }; 188 };
185 189
186 ExtensionShelf::Toolstrip::Toolstrip(ExtensionShelf* shelf, 190 ExtensionShelf::Toolstrip::Toolstrip(ExtensionShelf* shelf,
187 ExtensionHost* host) 191 ExtensionHost* host,
192 Extension::ToolstripInfo* info)
188 : host_(host), 193 : host_(host),
194 info_(info),
189 shelf_(shelf), 195 shelf_(shelf),
190 placeholder_view_(NULL), 196 placeholder_view_(NULL),
191 dragging_(false), 197 dragging_(false),
192 expanded_(false), 198 expanded_(false),
193 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)) { 199 ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)) {
194 DCHECK(host->view()); 200 DCHECK(host->view());
195 // We're owned by shelf_, not the bubble that we get inserted in and out of. 201 // We're owned by shelf_, not the bubble that we get inserted in and out of.
196 SetParentOwned(false); 202 SetParentOwned(false);
197 203
198 std::wstring name = UTF8ToWide(host_->extension()->name()); 204 std::wstring name = UTF8ToWide(host_->extension()->name());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // when we're dragging, draw the bottom border. 241 // when we're dragging, draw the bottom border.
236 canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1); 242 canvas->FillRectInt(kBorderColor, 0, height() - 1, width(), 1);
237 } 243 }
238 } 244 }
239 245
240 gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() { 246 gfx::Size ExtensionShelf::Toolstrip::GetPreferredSize() {
241 gfx::Size sz = title_->GetPreferredSize(); 247 gfx::Size sz = title_->GetPreferredSize();
242 int width = std::max(view()->width() + 2, sz.width()); 248 int width = std::max(view()->width() + 2, sz.width());
243 sz.set_width(width); 249 sz.set_width(width);
244 sz.Enlarge(kHandlePadding * 2, kHandlePadding * 2); 250 sz.Enlarge(kHandlePadding * 2, kHandlePadding * 2);
245 if (dragging_) { 251 if (dragging_ || expanded) {
246 gfx::Size extension_size = view()->GetPreferredSize(); 252 gfx::Size extension_size = view()->GetPreferredSize();
247 sz.Enlarge(0, extension_size.height() + 2); 253 sz.Enlarge(0, extension_size.height() + 2);
248 } else if (expanded_) {
249 // TODO(erikkay) these sizes are a temporary hack until we can get the
250 // size from the extension itself.
251 const int tempHeight = 200;
252 const int tempWidth = 400;
253 int width = std::max(sz.width(), tempWidth);
254 sz.set_width(width);
255 gfx::Size extension_size = view()->GetPreferredSize();
256 sz.Enlarge(0, extension_size.height() + 2 + tempHeight);
257 } 254 }
258 return sz; 255 return sz;
259 } 256 }
260 257
261 void ExtensionShelf::Toolstrip::Layout() { 258 void ExtensionShelf::Toolstrip::Layout() {
262 if (dragging_ || expanded_) { 259 if (dragging_ || expanded_) {
263 int y = title_->bounds().bottom() + kHandlePadding + 1; 260 int y = title_->bounds().bottom() + kHandlePadding + 1;
264 view()->SetBounds(1, y, view()->width(), view()->height()); 261 view()->SetBounds(1, y, view()->width(), view()->height());
265 } 262 }
266 } 263 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 305
309 // TODO(erikkay) as this gets dragged around, update the placeholder view 306 // TODO(erikkay) as this gets dragged around, update the placeholder view
310 // on the shelf to show where it will get dropped to. 307 // on the shelf to show where it will get dropped to.
311 handle_->MoveTo(screen.x(), screen.y()); 308 handle_->MoveTo(screen.x(), screen.y());
312 } 309 }
313 return true; 310 return true;
314 } 311 }
315 312
316 void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event, 313 void ExtensionShelf::Toolstrip::OnMouseReleased(const views::MouseEvent& event,
317 bool canceled) { 314 bool canceled) {
315 StopHandleTimer();
318 if (dragging_) { 316 if (dragging_) {
317 // Drop the toolstrip roughly where it is now.
319 views::View::OnMouseReleased(event, canceled); 318 views::View::OnMouseReleased(event, canceled);
320 dragging_ = false; 319 dragging_ = false;
321 // |this| and |shelf_| are in different view hierarchies, so we need to 320 // |this| and |shelf_| are in different view hierarchies, so we need to
322 // convert to screen coordinates and back again to map locations. 321 // convert to screen coordinates and back again to map locations.
323 gfx::Point loc = event.location(); 322 gfx::Point loc = event.location();
324 View::ConvertPointToScreen(this, &loc); 323 View::ConvertPointToScreen(this, &loc);
325 View::ConvertPointToView(NULL, shelf_, &loc); 324 View::ConvertPointToView(NULL, shelf_, &loc);
326 shelf_->DropExtension(this, loc, canceled); 325 shelf_->DropExtension(this, loc, canceled);
327 AttachToShelf(true); 326 AttachToShelf(true);
328 } else { 327 } else if (!canceled &&
329 #if 0 328 info_->mole.is_valid() && info_->toolstrip.is_valid()) {
330 // TODO(erikkay) implementation currently in progress 329 // Toggle mole to either expanded or collapsed.
331 expanded_ = !expanded_; 330 expanded_ = !expanded_;
331 view()->set_is_toolstrip(!expanded_);
332 if (expanded_) { 332 if (expanded_) {
333 gfx::Size extension_size = view()->GetPreferredSize();
334 extension_size.set_height(info_->mole_height);
335 view()->SetPreferredSize(extension_size);
336
337 host_->NavigateToURL(info_->mole);
333 StopHandleTimer(); 338 StopHandleTimer();
334 DetachFromShelf(false); 339 DetachFromShelf(false);
335 LayoutHandle(); 340 LayoutHandle();
336 } else { 341 } else {
342 gfx::Size extension_size = view()->GetPreferredSize();
343 extension_size.set_height(25); // TODO(erikkay) hard-coded?
Matt Perry 2009/07/24 23:11:11 any way we can get this information from the heigh
Erik does not do reviews 2009/07/26 00:34:46 yeah, I had a constant that I should have been usi
344 view()->SetPreferredSize(extension_size);
345
346 host_->NavigateToURL(info_->toolstrip);
337 AttachToShelf(false); 347 AttachToShelf(false);
338 } 348 }
339 #endif 349
350 // This is to prevent flickering as the page loads and lays out.
351 // Once the navigation is finished, ExtensionView will wind up setting
352 // visibility to true.
353 view()->SetVisible(false);
340 } 354 }
341 } 355 }
342 356
343 BrowserBubble* ExtensionShelf::Toolstrip::GetHandle() { 357 BrowserBubble* ExtensionShelf::Toolstrip::GetHandle() {
344 if (!handle_.get()) { 358 if (!handle_.get()) {
345 handle_.reset(new BrowserBubble(this, shelf_->GetWidget(), 359 handle_.reset(new BrowserBubble(this, shelf_->GetWidget(),
346 gfx::Point(0, 0))); 360 gfx::Point(0, 0)));
347 handle_->set_delegate(this); 361 handle_->set_delegate(this);
348 LayoutHandle(); 362 LayoutHandle();
349 } 363 }
(...skipping 12 matching lines...) Expand all
362 &origin); 376 &origin);
363 } else { 377 } else {
364 views::View::ConvertPointToWidget(view(), &origin); 378 views::View::ConvertPointToWidget(view(), &origin);
365 } 379 }
366 SetBounds(0, 0, handle_width, height()); 380 SetBounds(0, 0, handle_width, height());
367 handle_->SetBounds(origin.x(), origin.y(), handle_width, height()); 381 handle_->SetBounds(origin.x(), origin.y(), handle_width, height());
368 handle_->ResizeToView(); 382 handle_->ResizeToView();
369 } 383 }
370 384
371 void ExtensionShelf::Toolstrip::ChildPreferredSizeChanged(View* child) { 385 void ExtensionShelf::Toolstrip::ChildPreferredSizeChanged(View* child) {
372 if (child == view()) 386 if (child == view()) {
373 child->SizeToPreferredSize(); 387 child->SizeToPreferredSize();
388 Layout();
389 }
374 } 390 }
375 391
376 void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved(BrowserBubble* bubble) 392 void ExtensionShelf::Toolstrip::BubbleBrowserWindowMoved(BrowserBubble* bubble)
377 { 393 {
378 HideShelfHandle(0); 394 HideShelfHandle(0);
379 } 395 }
380 396
381 void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosed(BrowserBubble* bubble) 397 void ExtensionShelf::Toolstrip::BubbleBrowserWindowClosing(BrowserBubble* bubble )
382 { 398 {
383 HideShelfHandle(0); 399 DoHideShelfHandle();
384 } 400 }
385 401
386 void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) { 402 void ExtensionShelf::Toolstrip::DetachFromShelf(bool browserDetach) {
387 DCHECK(!placeholder_view_); 403 DCHECK(!placeholder_view_);
388 if (browserDetach && handle_->attached()) 404 if (browserDetach && handle_->attached())
389 handle_->DetachFromBrowser(); 405 handle_->DetachFromBrowser();
390 406
391 // Construct a placeholder view to replace the view. 407 // Construct a placeholder view to replace the view.
392 placeholder_view_ = new PlaceholderView(); 408 placeholder_view_ = new PlaceholderView();
393 placeholder_view_->SetBounds(view()->bounds()); 409 placeholder_view_->SetBounds(view()->bounds());
(...skipping 28 matching lines...) Expand all
422 438
423 void ExtensionShelf::Toolstrip::DoShowShelfHandle() { 439 void ExtensionShelf::Toolstrip::DoShowShelfHandle() {
424 GetHandle(); 440 GetHandle();
425 if (!handle_->visible()) { 441 if (!handle_->visible()) {
426 LayoutHandle(); 442 LayoutHandle();
427 handle_->Show(); 443 handle_->Show();
428 } 444 }
429 } 445 }
430 446
431 void ExtensionShelf::Toolstrip::DoHideShelfHandle() { 447 void ExtensionShelf::Toolstrip::DoHideShelfHandle() {
432 if (!handle_visible() || dragging_ || expanded_) 448 if (!handle_visible())
433 return; 449 return;
434 handle_->Hide(); 450 handle_->Hide();
435 if (handle_->attached()) 451 if (handle_->attached())
436 handle_->DetachFromBrowser(); 452 handle_->DetachFromBrowser();
437 handle_.reset(NULL); 453 handle_.reset(NULL);
438 } 454 }
439 455
440 void ExtensionShelf::Toolstrip::StopHandleTimer() { 456 void ExtensionShelf::Toolstrip::StopHandleTimer() {
441 if (!timer_factory_.empty()) 457 if (!timer_factory_.empty())
442 timer_factory_.RevokeAll(); 458 timer_factory_.RevokeAll();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 name->assign(accessible_name_); 595 name->assign(accessible_name_);
580 return true; 596 return true;
581 } 597 }
582 return false; 598 return false;
583 } 599 }
584 600
585 void ExtensionShelf::SetAccessibleName(const std::wstring& name) { 601 void ExtensionShelf::SetAccessibleName(const std::wstring& name) {
586 accessible_name_.assign(name); 602 accessible_name_.assign(name);
587 } 603 }
588 604
589 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host, int index) { 605 void ExtensionShelf::ToolstripInsertedAt(ExtensionHost* host,
590 model_->SetToolstripDataAt(index, new Toolstrip(this, host)); 606 int index) {
607 model_->SetToolstripDataAt(index,
608 new Toolstrip(this, host, model_->ToolstripInfoAt(index)));
591 609
592 bool had_views = GetChildViewCount() > 0; 610 bool had_views = GetChildViewCount() > 0;
593 ExtensionView* view = host->view(); 611 ExtensionView* view = host->view();
594 if (!background_.empty()) 612 if (!background_.empty())
595 view->SetBackground(background_); 613 view->SetBackground(background_);
596 AddChildView(view); 614 AddChildView(view);
597 view->SetContainer(this); 615 view->SetContainer(this);
598 if (!had_views) 616 if (!had_views)
599 PreferredSizeChanged(); 617 PreferredSizeChanged();
600 Layout(); 618 Layout();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 748 }
731 NOTREACHED(); 749 NOTREACHED();
732 return NULL; 750 return NULL;
733 } 751 }
734 752
735 void ExtensionShelf::LoadFromModel() { 753 void ExtensionShelf::LoadFromModel() {
736 int count = model_->count(); 754 int count = model_->count();
737 for (int i = 0; i < count; ++i) 755 for (int i = 0; i < count; ++i)
738 ToolstripInsertedAt(model_->ToolstripAt(i), i); 756 ToolstripInsertedAt(model_->ToolstripAt(i), i);
739 } 757 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698