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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_popup.cc

Issue 5254007: Addition of 'maxSize' to experimental popup extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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
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_popup.h" 5 #include "chrome/browser/views/extensions/extension_popup.h"
6 6
7 #include "chrome/browser/browser_list.h" 7 #include "chrome/browser/browser_list.h"
8 #include "chrome/browser/browser_window.h" 8 #include "chrome/browser/browser_window.h"
9 #include "chrome/browser/debugger/devtools_manager.h" 9 #include "chrome/browser/debugger/devtools_manager.h"
10 #include "chrome/browser/debugger/devtools_toggle_action.h" 10 #include "chrome/browser/debugger/devtools_toggle_action.h"
(...skipping 16 matching lines...) Expand all
27 #include "views/widget/widget_gtk.h" 27 #include "views/widget/widget_gtk.h"
28 #endif 28 #endif
29 29
30 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/wm_ipc.h" 31 #include "chrome/browser/chromeos/wm_ipc.h"
32 #include "cros/chromeos_wm_ipc_enums.h" 32 #include "cros/chromeos_wm_ipc_enums.h"
33 #endif 33 #endif
34 34
35 using views::Widget; 35 using views::Widget;
36 36
37 // The minimum/maximum dimensions of the popup. 37 // The minimum, and default maximum dimensions of the popup.
38 // The minimum is just a little larger than the size of the button itself. 38 // The minimum is just a little larger than the size of the button itself.
39 // The maximum is an arbitrary number that should be smaller than most screens. 39 // The default maximum is an arbitrary number that should be smaller than most
40 // screens.
40 const int ExtensionPopup::kMinWidth = 25; 41 const int ExtensionPopup::kMinWidth = 25;
41 const int ExtensionPopup::kMinHeight = 25; 42 const int ExtensionPopup::kMinHeight = 25;
42 const int ExtensionPopup::kMaxWidth = 800; 43 const int ExtensionPopup::kMaxWidth = 800;
43 const int ExtensionPopup::kMaxHeight = 600; 44 const int ExtensionPopup::kMaxHeight = 600;
44 45
45 namespace { 46 namespace {
46 47
47 // The width, in pixels, of the black-border on a popup. 48 // The width, in pixels, of the black-border on a popup.
48 const int kPopupBorderWidth = 1; 49 const int kPopupBorderWidth = 1;
49 50
(...skipping 19 matching lines...) Expand all
69 relative_to_(relative_to), 70 relative_to_(relative_to),
70 extension_host_(host), 71 extension_host_(host),
71 activate_on_show_(activate_on_show), 72 activate_on_show_(activate_on_show),
72 inspect_with_devtools_(inspect_with_devtools), 73 inspect_with_devtools_(inspect_with_devtools),
73 close_on_lost_focus_(true), 74 close_on_lost_focus_(true),
74 closing_(false), 75 closing_(false),
75 border_widget_(NULL), 76 border_widget_(NULL),
76 border_(NULL), 77 border_(NULL),
77 border_view_(NULL), 78 border_view_(NULL),
78 popup_chrome_(chrome), 79 popup_chrome_(chrome),
80 max_size_(kMaxWidth, kMaxHeight),
79 observer_(observer), 81 observer_(observer),
80 anchor_position_(arrow_location), 82 anchor_position_(arrow_location),
81 instance_lifetime_(new InternalRefCounter()){ 83 instance_lifetime_(new InternalRefCounter()){
82 AddRef(); // Balanced in Close(); 84 AddRef(); // Balanced in Close();
83 set_delegate(this); 85 set_delegate(this);
84 host->view()->SetContainer(this); 86 host->view()->SetContainer(this);
85 87
86 // We wait to show the popup until the contained host finishes loading. 88 // We wait to show the popup until the contained host finishes loading.
87 registrar_.Add(this, 89 registrar_.Add(this,
88 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, 90 NotificationType::EXTENSION_HOST_DID_STOP_LOADING,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 284
283 break; 285 break;
284 default: 286 default:
285 NOTREACHED() << L"Received unexpected notification"; 287 NOTREACHED() << L"Received unexpected notification";
286 } 288 }
287 } 289 }
288 290
289 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) { 291 void ExtensionPopup::OnExtensionPreferredSizeChanged(ExtensionView* view) {
290 // Constrain the size to popup min/max. 292 // Constrain the size to popup min/max.
291 gfx::Size sz = view->GetPreferredSize(); 293 gfx::Size sz = view->GetPreferredSize();
294
292 view->SetBounds(view->x(), view->y(), 295 view->SetBounds(view->x(), view->y(),
293 std::max(kMinWidth, std::min(kMaxWidth, sz.width())), 296 std::max(kMinWidth, std::min(max_size_.width(), sz.width())),
294 std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); 297 std::max(kMinHeight, std::min(max_size_.height(), sz.height())));
295 298
296 // If popup_chrome_ == RECTANGLE_CHROME, the border is drawn in the client 299 // If popup_chrome_ == RECTANGLE_CHROME, the border is drawn in the client
297 // area of the ExtensionView, rather than in a window which sits behind it. 300 // area of the ExtensionView, rather than in a window which sits behind it.
298 // In this case, the actual size of the view must be enlarged so that the 301 // In this case, the actual size of the view must be enlarged so that the
299 // web contents portion of the view gets its full PreferredSize area. 302 // web contents portion of the view gets its full PreferredSize area.
300 if (view->border()) { 303 if (view->border()) {
301 gfx::Insets border_insets; 304 gfx::Insets border_insets;
302 view->border()->GetInsets(&border_insets); 305 view->border()->GetInsets(&border_insets);
303 306
304 gfx::Rect bounds(view->bounds()); 307 gfx::Rect bounds(view->bounds());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 383
381 ExtensionHost* host = manager->CreatePopup(url, browser); 384 ExtensionHost* host = manager->CreatePopup(url, browser);
382 if (observer) 385 if (observer)
383 observer->ExtensionHostCreated(host); 386 observer->ExtensionHostCreated(host);
384 387
385 ExtensionPopup* popup = new ExtensionPopup(host, frame_widget, relative_to, 388 ExtensionPopup* popup = new ExtensionPopup(host, frame_widget, relative_to,
386 arrow_location, activate_on_show, 389 arrow_location, activate_on_show,
387 inspect_with_devtools, chrome, 390 inspect_with_devtools, chrome,
388 observer); 391 observer);
389 392
393 if (observer)
394 observer->ExtensionPopupCreated(popup);
395
390 // If the host had somehow finished loading, then we'd miss the notification 396 // If the host had somehow finished loading, then we'd miss the notification
391 // and not show. This seems to happen in single-process mode. 397 // and not show. This seems to happen in single-process mode.
392 if (host->did_stop_loading()) 398 if (host->did_stop_loading())
393 popup->Show(activate_on_show); 399 popup->Show(activate_on_show);
394 400
395 return popup; 401 return popup;
396 } 402 }
397 403
398 void ExtensionPopup::Close() { 404 void ExtensionPopup::Close() {
399 if (closing_) 405 if (closing_)
(...skipping 14 matching lines...) Expand all
414 DCHECK(closing_) << "ExtensionPopup to be destroyed before being closed."; 420 DCHECK(closing_) << "ExtensionPopup to be destroyed before being closed.";
415 ExtensionPopup::Observer* observer = observer_; 421 ExtensionPopup::Observer* observer = observer_;
416 delete this; 422 delete this;
417 423
418 // |this| is passed only as a 'cookie'. The observer API explicitly takes a 424 // |this| is passed only as a 'cookie'. The observer API explicitly takes a
419 // void* argument to emphasize this. 425 // void* argument to emphasize this.
420 if (observer) 426 if (observer)
421 observer->ExtensionPopupClosed(this); 427 observer->ExtensionPopupClosed(this);
422 } 428 }
423 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698