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

Side by Side Diff: chrome/browser/ui/views/constrained_window_views.cc

Issue 11044020: Make Web Intents picker in Views conform to latest mocks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 8 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/constrained_window_views.h" 5 #include "chrome/browser/ui/views/constrained_window_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/platform_util.h" 12 #include "chrome/browser/platform_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/constrained_window_constants.h"
16 #include "chrome/browser/ui/constrained_window_tab_helper.h" 17 #include "chrome/browser/ui/constrained_window_tab_helper.h"
17 #include "chrome/browser/ui/toolbar/toolbar_model.h" 18 #include "chrome/browser/ui/toolbar/toolbar_model.h"
18 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" 19 #include "chrome/browser/ui/views/constrained_window_frame_simple.h"
19 #include "chrome/browser/ui/views/frame/browser_view.h" 20 #include "chrome/browser/ui/views/frame/browser_view.h"
20 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h"
27 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_view.h" 29 #include "content/public/browser/web_contents_view.h"
25 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
27 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
28 #include "grit/ui_resources.h" 33 #include "grit/ui_resources.h"
29 #include "net/base/net_util.h" 34 #include "net/base/net_util.h"
30 #include "ui/aura/client/aura_constants.h" 35 #include "ui/aura/client/aura_constants.h"
31 #include "ui/base/hit_test.h" 36 #include "ui/base/hit_test.h"
32 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 161 }
157 162
158 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT]; 163 static gfx::ImageSkia* images_[FRAME_PART_IMAGE_COUNT];
159 164
160 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); 165 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources);
161 }; 166 };
162 167
163 gfx::ImageSkia* XPWindowResources::images_[]; 168 gfx::ImageSkia* XPWindowResources::images_[];
164 gfx::ImageSkia* VistaWindowResources::images_[]; 169 gfx::ImageSkia* VistaWindowResources::images_[];
165 170
166 ////////////////////////////////////////////////////////////////////////////////
167 // ConstrainedWindowFrameView
168
169 class ConstrainedWindowFrameView : public views::NonClientFrameView, 171 class ConstrainedWindowFrameView : public views::NonClientFrameView,
170 public views::ButtonListener { 172 public views::ButtonListener {
171 public: 173 public:
172 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); 174 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container);
173 virtual ~ConstrainedWindowFrameView(); 175 virtual ~ConstrainedWindowFrameView();
174 176
175 void UpdateWindowTitle(); 177 void UpdateWindowTitle();
176 178
177 // Overridden from views::NonClientFrameView: 179 // Overridden from views::NonClientFrameView:
178 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 180 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 const int kIconMinimumSize = 16; 280 const int kIconMinimumSize = 16;
279 // The title text starts 2 px from the right edge of the left frame border. 281 // The title text starts 2 px from the right edge of the left frame border.
280 const int kTitleLeftSpacing = 2; 282 const int kTitleLeftSpacing = 2;
281 // There is a 5 px gap between the title text and the caption buttons. 283 // There is a 5 px gap between the title text and the caption buttons.
282 const int kTitleCaptionSpacing = 5; 284 const int kTitleCaptionSpacing = 5;
283 285
284 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); 286 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0);
285 287
286 } // namespace 288 } // namespace
287 289
288 ////////////////////////////////////////////////////////////////////////////////
289 // ConstrainedWindowFrameView, public:
290
291 ConstrainedWindowFrameView::ConstrainedWindowFrameView( 290 ConstrainedWindowFrameView::ConstrainedWindowFrameView(
292 ConstrainedWindowViews* container) 291 ConstrainedWindowViews* container)
293 : NonClientFrameView(), 292 : NonClientFrameView(),
294 container_(container), 293 container_(container),
295 close_button_(new views::ImageButton(this)), 294 close_button_(new views::ImageButton(this)),
296 frame_background_(new views::FrameBackground()) { 295 frame_background_(new views::FrameBackground()) {
297 InitClass(); 296 InitClass();
298 InitWindowResources(); 297 InitWindowResources();
299 298
300 // Constrained windows always use the custom frame - they just have a 299 // Constrained windows always use the custom frame - they just have a
(...skipping 12 matching lines...) Expand all
313 AddChildView(close_button_); 312 AddChildView(close_button_);
314 } 313 }
315 314
316 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() { 315 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() {
317 } 316 }
318 317
319 void ConstrainedWindowFrameView::UpdateWindowTitle() { 318 void ConstrainedWindowFrameView::UpdateWindowTitle() {
320 SchedulePaintInRect(title_bounds_); 319 SchedulePaintInRect(title_bounds_);
321 } 320 }
322 321
323 ////////////////////////////////////////////////////////////////////////////////
324 // ConstrainedWindowFrameView, views::NonClientFrameView implementation:
325
326 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const { 322 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const {
327 return client_view_bounds_; 323 return client_view_bounds_;
328 } 324 }
329 325
330 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds( 326 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds(
331 const gfx::Rect& client_bounds) const { 327 const gfx::Rect& client_bounds) const {
332 int top_height = NonClientTopBorderHeight(); 328 int top_height = NonClientTopBorderHeight();
333 int border_thickness = NonClientBorderThickness(); 329 int border_thickness = NonClientBorderThickness();
334 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), 330 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
335 std::max(0, client_bounds.y() - top_height), 331 std::max(0, client_bounds.y() - top_height),
(...skipping 28 matching lines...) Expand all
364 // Fall back to the caption if no other component matches. 360 // Fall back to the caption if no other component matches.
365 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 361 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
366 } 362 }
367 363
368 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size, 364 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size,
369 gfx::Path* window_mask) { 365 gfx::Path* window_mask) {
370 DCHECK(window_mask); 366 DCHECK(window_mask);
371 views::GetDefaultWindowMask(size, window_mask); 367 views::GetDefaultWindowMask(size, window_mask);
372 } 368 }
373 369
374 ////////////////////////////////////////////////////////////////////////////////
375 // ConstrainedWindowFrameView, views::View implementation:
376
377 void ConstrainedWindowFrameView::OnPaint(gfx::Canvas* canvas) { 370 void ConstrainedWindowFrameView::OnPaint(gfx::Canvas* canvas) {
378 PaintFrameBorder(canvas); 371 PaintFrameBorder(canvas);
379 PaintTitleBar(canvas); 372 PaintTitleBar(canvas);
380 PaintClientEdge(canvas); 373 PaintClientEdge(canvas);
381 } 374 }
382 375
383 void ConstrainedWindowFrameView::Layout() { 376 void ConstrainedWindowFrameView::Layout() {
384 LayoutWindowControls(); 377 LayoutWindowControls();
385 LayoutTitleBar(); 378 LayoutTitleBar();
386 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); 379 client_view_bounds_ = CalculateClientAreaBounds(width(), height());
387 } 380 }
388 381
389 void ConstrainedWindowFrameView::OnThemeChanged() { 382 void ConstrainedWindowFrameView::OnThemeChanged() {
390 InitWindowResources(); 383 InitWindowResources();
391 } 384 }
392 385
393 ////////////////////////////////////////////////////////////////////////////////
394 // ConstrainedWindowFrameView, views::ButtonListener implementation:
395
396 void ConstrainedWindowFrameView::ButtonPressed( 386 void ConstrainedWindowFrameView::ButtonPressed(
397 views::Button* sender, const ui::Event& event) { 387 views::Button* sender, const ui::Event& event) {
398 if (sender == close_button_) 388 if (sender == close_button_)
399 container_->CloseConstrainedWindow(); 389 container_->CloseConstrainedWindow();
400 } 390 }
401 391
402 ////////////////////////////////////////////////////////////////////////////////
403 // ConstrainedWindowFrameView, private:
404
405 int ConstrainedWindowFrameView::NonClientBorderThickness() const { 392 int ConstrainedWindowFrameView::NonClientBorderThickness() const {
406 return kFrameBorderThickness + kClientEdgeThickness; 393 return kFrameBorderThickness + kClientEdgeThickness;
407 } 394 }
408 395
409 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const { 396 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const {
410 return std::max(kFrameBorderThickness + IconSize(), 397 return std::max(kFrameBorderThickness + IconSize(),
411 kFrameShadowThickness + kCaptionButtonHeightWithPadding) + 398 kFrameShadowThickness + kCaptionButtonHeightWithPadding) +
412 TitlebarBottomThickness(); 399 TitlebarBottomThickness();
413 } 400 }
414 401
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 if (sender == close_button()) 554 if (sender == close_button())
568 container_->CloseConstrainedWindow(); 555 container_->CloseConstrainedWindow();
569 } 556 }
570 557
571 private: 558 private:
572 ConstrainedWindowViews* container_; // not owned 559 ConstrainedWindowViews* container_; // not owned
573 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); 560 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh);
574 }; 561 };
575 #endif // defined(USE_ASH) 562 #endif // defined(USE_ASH)
576 563
577 ////////////////////////////////////////////////////////////////////////////////
578 // ConstrainedWindowViews, public:
579
580 ConstrainedWindowViews::ConstrainedWindowViews( 564 ConstrainedWindowViews::ConstrainedWindowViews(
581 content::WebContents* web_contents, 565 content::WebContents* web_contents,
582 views::WidgetDelegate* widget_delegate, 566 views::WidgetDelegate* widget_delegate,
583 bool enable_chrome_style) 567 bool enable_chrome_style,
568 const gfx::Insets& client_insets)
584 : WebContentsObserver(web_contents), 569 : WebContentsObserver(web_contents),
585 web_contents_(web_contents), 570 web_contents_(web_contents),
571 enable_chrome_style_(enable_chrome_style),
572 client_insets_(client_insets),
586 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_( 573 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_(
587 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))), 574 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) {
588 enable_chrome_style_(enable_chrome_style) {
589 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 575 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
590 params.delegate = widget_delegate; 576 params.delegate = widget_delegate;
591 params.native_widget = native_constrained_window_->AsNativeWidget(); 577 params.native_widget = native_constrained_window_->AsNativeWidget();
592 params.child = true; 578 params.child = true;
593 ConstrainedWindowTabHelper::CreateForWebContents(web_contents); 579 ConstrainedWindowTabHelper::CreateForWebContents(web_contents);
594 580
595 if (enable_chrome_style_) { 581 if (enable_chrome_style_) {
596 params.parent_widget = Widget::GetTopLevelWidgetForNativeView( 582 params.parent_widget = Widget::GetTopLevelWidgetForNativeView(
597 web_contents->GetView()->GetNativeView()); 583 web_contents_->GetView()->GetNativeView());
598 } else { 584 } else {
599 params.parent = web_contents->GetNativeView(); 585 params.parent = web_contents_->GetNativeView();
600 } 586 }
601 587
602 #if defined(USE_ASH) 588 #if defined(USE_ASH)
603 // Ash window headers can be transparent. 589 // Ash window headers can be transparent.
604 params.transparent = true; 590 params.transparent = true;
605 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent()); 591 ash::SetChildWindowVisibilityChangesAnimated(params.GetParent());
606 // No animations should get performed on the window since that will re-order 592 // No animations should get performed on the window since that will re-order
607 // the window stack which will then cause many problems. 593 // the window stack which will then cause many problems.
608 if (params.parent && params.parent->parent()) { 594 if (params.parent && params.parent->parent()) {
609 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, 595 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey,
610 true); 596 true);
611 } 597 }
612 #endif 598 #endif
613 Init(params); 599 Init(params);
614 600
615 if (enable_chrome_style_) { 601 if (enable_chrome_style_) {
616 // Set the dialog background color. 602 // Set the dialog background color.
617 if (widget_delegate && widget_delegate->AsDialogDelegate()) { 603 if (widget_delegate && widget_delegate->AsDialogDelegate()) {
618 views::Background* background = views::Background::CreateSolidBackground( 604 views::Background* background = views::Background::CreateSolidBackground(
619 ConstrainedWindow::GetBackgroundColor()); 605 ConstrainedWindow::GetBackgroundColor());
620 views::DialogClientView* dialog_client_view = 606 views::DialogClientView* dialog_client_view =
621 widget_delegate->AsDialogDelegate()->GetDialogClientView(); 607 widget_delegate->AsDialogDelegate()->GetDialogClientView();
622 if (dialog_client_view) 608 if (dialog_client_view)
623 dialog_client_view->set_background(background); 609 dialog_client_view->set_background(background);
624 } 610 }
625 PositionChromeStyleWindow(); 611 PositionChromeStyleWindow(GetRootView()->bounds().size());
612 registrar_.Add(this,
613 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
614 content::Source<content::WebContents>(web_contents));
626 } 615 }
627 616
628 ConstrainedWindowTabHelper* constrained_window_tab_helper = 617 ConstrainedWindowTabHelper* constrained_window_tab_helper =
629 ConstrainedWindowTabHelper::FromWebContents(web_contents_); 618 ConstrainedWindowTabHelper::FromWebContents(web_contents_);
630 constrained_window_tab_helper->AddConstrainedDialog(this); 619 constrained_window_tab_helper->AddConstrainedDialog(this);
631 #if defined(USE_ASH) 620 #if defined(USE_ASH)
632 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); 621 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true);
633 #endif 622 #endif
634 } 623 }
635 624
636 ConstrainedWindowViews::~ConstrainedWindowViews() { 625 ConstrainedWindowViews::~ConstrainedWindowViews() {
637 } 626 }
638 627
639 ////////////////////////////////////////////////////////////////////////////////
640 // ConstrainedWindowViews, ConstrainedWindow implementation:
641
642 void ConstrainedWindowViews::ShowConstrainedWindow() { 628 void ConstrainedWindowViews::ShowConstrainedWindow() {
643 Show(); 629 Show();
644 FocusConstrainedWindow(); 630 FocusConstrainedWindow();
645 } 631 }
646 632
647 void ConstrainedWindowViews::CloseConstrainedWindow() { 633 void ConstrainedWindowViews::CloseConstrainedWindow() {
648 #if defined(USE_ASH) 634 #if defined(USE_ASH)
649 gfx::NativeView view = web_contents_->GetNativeView(); 635 gfx::NativeView view = web_contents_->GetNativeView();
650 // Allow the parent to animate again. 636 // Allow the parent to animate again.
651 if (view && view->parent()) 637 if (view && view->parent())
(...skipping 25 matching lines...) Expand all
677 663
678 void ConstrainedWindowViews::NotifyTabHelperWillClose() { 664 void ConstrainedWindowViews::NotifyTabHelperWillClose() {
679 if (!web_contents_) 665 if (!web_contents_)
680 return; 666 return;
681 667
682 ConstrainedWindowTabHelper* constrained_window_tab_helper = 668 ConstrainedWindowTabHelper* constrained_window_tab_helper =
683 ConstrainedWindowTabHelper::FromWebContents(web_contents_); 669 ConstrainedWindowTabHelper::FromWebContents(web_contents_);
684 constrained_window_tab_helper->WillClose(this); 670 constrained_window_tab_helper->WillClose(this);
685 } 671 }
686 672
687 ////////////////////////////////////////////////////////////////////////////////
688 // ConstrainedWindowViews, views::Widget overrides:
689
690 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) { 673 void ConstrainedWindowViews::CenterWindow(const gfx::Size& size) {
691 Widget::CenterWindow(size);
692 if (enable_chrome_style_) 674 if (enable_chrome_style_)
693 PositionChromeStyleWindow(); 675 PositionChromeStyleWindow(size);
676 else
677 Widget::CenterWindow(size);
694 } 678 }
695 679
696 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { 680 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() {
697 if (enable_chrome_style_) { 681 if (enable_chrome_style_) {
698 return new ConstrainedWindowFrameSimple(this); 682 ConstrainedWindowFrameSimple* frame =
699 } else { 683 new ConstrainedWindowFrameSimple(this);
684 frame->set_border(views::Border::CreateEmptyBorder(
685 client_insets_.top(),
686 client_insets_.left(),
687 client_insets_.bottom(),
688 client_insets_.right()));
689 return frame;
690 }
700 #if defined(USE_ASH) 691 #if defined(USE_ASH)
701 CommandLine* command_line = CommandLine::ForCurrentProcess(); 692 CommandLine* command_line = CommandLine::ForCurrentProcess();
702 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames)) 693 if (command_line->HasSwitch(ash::switches::kAuraGoogleDialogFrames))
703 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); 694 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this);
704 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; 695 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh;
705 frame->Init(this); 696 frame->Init(this);
706 return frame; 697 return frame;
707 #endif 698 #endif
708 return new ConstrainedWindowFrameView(this); 699 return new ConstrainedWindowFrameView(this);
709 }
710 } 700 }
711 701
712 //////////////////////////////////////////////////////////////////////////////// 702 // static
713 // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: 703 gfx::Insets ConstrainedWindowViews::GetDefaultInsets() {
704 const int kHeaderHeight = 26;
Peter Kasting 2012/10/16 02:26:53 Could this value be calculated on the fly by the C
please use gerrit instead 2012/10/16 16:29:38 I have added an enum ConstrainedWindowViews::Chrom
705 return gfx::Insets(
706 ConstrainedWindowConstants::kClientTopPadding + kHeaderHeight,
707 ConstrainedWindowConstants::kHorizontalPadding,
708 ConstrainedWindowConstants::kClientBottomPadding,
709 ConstrainedWindowConstants::kHorizontalPadding);
710 }
714 711
715 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { 712 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() {
716 NotifyTabHelperWillClose(); 713 NotifyTabHelperWillClose();
717 } 714 }
718 715
719 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { 716 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() {
720 Activate(); 717 Activate();
721 } 718 }
722 719
723 views::internal::NativeWidgetDelegate* 720 views::internal::NativeWidgetDelegate*
724 ConstrainedWindowViews::AsNativeWidgetDelegate() { 721 ConstrainedWindowViews::AsNativeWidgetDelegate() {
725 return this; 722 return this;
726 } 723 }
727 724
728 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) { 725 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) {
729 // Prevent a constrained window to be moved by the user. 726 // Prevent a constrained window to be moved by the user.
730 return HTNOWHERE; 727 return HTNOWHERE;
731 } 728 }
732 729
733 void ConstrainedWindowViews::PositionChromeStyleWindow() {
734 DCHECK(enable_chrome_style_);
735 gfx::Rect bounds = GetRootView()->bounds();
736 ConstrainedWindowTabHelperDelegate* tab_helper_delegate =
737 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate();
738
739 BrowserWindow* browser_window =
740 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL;
741 int top_y;
742 if (browser_window && browser_window->GetConstrainedWindowTopY(&top_y)) {
743 bounds.set_y(top_y);
744 bounds.set_x(
745 browser_window->GetBounds().width() / 2 - bounds.width() / 2);
746 SetBounds(bounds);
747 }
748 }
749
750 ////////////////////////////////////////////////////////////////////////////////
751 // ConstrainedWindowViews, content::WebContentsObserver implementation:
752
753 void ConstrainedWindowViews::WebContentsDestroyed( 730 void ConstrainedWindowViews::WebContentsDestroyed(
754 content::WebContents* web_contents) { 731 content::WebContents* web_contents) {
755 web_contents_ = NULL; 732 web_contents_ = NULL;
756 } 733 }
734
735 void ConstrainedWindowViews::Observe(
736 int type,
737 const content::NotificationSource& source,
738 const content::NotificationDetails& details) {
739 DCHECK(enable_chrome_style_);
740 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED);
741 if (*content::Details<bool>(details).ptr())
742 Show();
743 else
744 Hide();
745 }
746
747 void ConstrainedWindowViews::PositionChromeStyleWindow(const gfx::Size& size) {
748 DCHECK(enable_chrome_style_);
749 gfx::Rect bounds(GetRootView()->bounds().origin(), size);
750 ConstrainedWindowTabHelperDelegate* tab_helper_delegate =
751 ConstrainedWindowTabHelper::FromWebContents(web_contents_)->delegate();
752 BrowserWindow* browser_window =
753 tab_helper_delegate ? tab_helper_delegate->GetBrowserWindow() : NULL;
754 if (browser_window) {
755 bounds.set_x(browser_window->GetBounds().width() / 2 - bounds.width() / 2);
756 int top_y;
757 if (browser_window->GetConstrainedWindowTopY(&top_y))
758 bounds.set_y(top_y);
759 }
760 SetBounds(bounds);
761 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698