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

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

Issue 12045037: Refactor modality-specific behavior from ConstrainedWindowViews to WebContentsModalDialogManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
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"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); 162 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources);
163 }; 163 };
164 164
165 gfx::ImageSkia* XPWindowResources::images_[]; 165 gfx::ImageSkia* XPWindowResources::images_[];
166 gfx::ImageSkia* VistaWindowResources::images_[]; 166 gfx::ImageSkia* VistaWindowResources::images_[];
167 167
168 class ConstrainedWindowFrameView : public views::NonClientFrameView, 168 class ConstrainedWindowFrameView : public views::NonClientFrameView,
169 public views::ButtonListener { 169 public views::ButtonListener {
170 public: 170 public:
171 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); 171 ConstrainedWindowFrameView(ConstrainedWindowViews* container,
172 bool browser_is_off_the_record);
172 virtual ~ConstrainedWindowFrameView(); 173 virtual ~ConstrainedWindowFrameView();
173 174
174 void UpdateWindowTitle(); 175 void UpdateWindowTitle();
175 176
176 // Overridden from views::NonClientFrameView: 177 // Overridden from views::NonClientFrameView:
177 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 178 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
178 virtual gfx::Rect GetWindowBoundsForClientBounds( 179 virtual gfx::Rect GetWindowBoundsForClientBounds(
179 const gfx::Rect& client_bounds) const OVERRIDE; 180 const gfx::Rect& client_bounds) const OVERRIDE;
180 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 181 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
181 virtual void GetWindowMask(const gfx::Size& size, 182 virtual void GetWindowMask(const gfx::Size& size,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void PaintClientEdge(gfx::Canvas* canvas); 218 void PaintClientEdge(gfx::Canvas* canvas);
218 219
219 // Layout various sub-components of this view. 220 // Layout various sub-components of this view.
220 void LayoutWindowControls(); 221 void LayoutWindowControls();
221 void LayoutTitleBar(); 222 void LayoutTitleBar();
222 223
223 // Returns the bounds of the client area for the specified view size. 224 // Returns the bounds of the client area for the specified view size.
224 gfx::Rect CalculateClientAreaBounds(int width, int height) const; 225 gfx::Rect CalculateClientAreaBounds(int width, int height) const;
225 226
226 SkColor GetTitleColor() const { 227 SkColor GetTitleColor() const {
227 return container_->owner()->GetBrowserContext()->IsOffTheRecord() 228 return browser_is_off_the_record_
228 #if defined(OS_WIN) && !defined(USE_AURA) 229 #if defined(OS_WIN) && !defined(USE_AURA)
229 || !ui::win::IsAeroGlassEnabled() 230 || !ui::win::IsAeroGlassEnabled()
230 #endif 231 #endif
231 ? SK_ColorWHITE : SK_ColorBLACK; 232 ? SK_ColorWHITE : SK_ColorBLACK;
232 } 233 }
233 234
234 // Loads the appropriate set of WindowResources for the frame view. 235 // Loads the appropriate set of WindowResources for the frame view.
235 void InitWindowResources(); 236 void InitWindowResources();
236 237
237 ConstrainedWindowViews* container_; 238 ConstrainedWindowViews* container_;
238 239
240 bool browser_is_off_the_record_;
241
239 scoped_ptr<views::WindowResources> resources_; 242 scoped_ptr<views::WindowResources> resources_;
240 243
241 gfx::Rect title_bounds_; 244 gfx::Rect title_bounds_;
242 245
243 views::ImageButton* close_button_; 246 views::ImageButton* close_button_;
244 247
245 // The bounds of the ClientView. 248 // The bounds of the ClientView.
246 gfx::Rect client_view_bounds_; 249 gfx::Rect client_view_bounds_;
247 250
248 // Background painter for the frame. 251 // Background painter for the frame.
(...skipping 29 matching lines...) Expand all
278 // 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.
279 const int kTitleLeftSpacing = 2; 282 const int kTitleLeftSpacing = 2;
280 // 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.
281 const int kTitleCaptionSpacing = 5; 284 const int kTitleCaptionSpacing = 5;
282 285
283 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); 286 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0);
284 287
285 } // namespace 288 } // namespace
286 289
287 ConstrainedWindowFrameView::ConstrainedWindowFrameView( 290 ConstrainedWindowFrameView::ConstrainedWindowFrameView(
288 ConstrainedWindowViews* container) 291 ConstrainedWindowViews* container, bool browser_is_off_the_record)
289 : NonClientFrameView(), 292 : NonClientFrameView(),
290 container_(container), 293 container_(container),
294 browser_is_off_the_record_(browser_is_off_the_record),
291 close_button_(new views::ImageButton(this)), 295 close_button_(new views::ImageButton(this)),
292 frame_background_(new views::FrameBackground()) { 296 frame_background_(new views::FrameBackground()) {
293 InitClass(); 297 InitClass();
294 InitWindowResources(); 298 InitWindowResources();
295 299
296 // Constrained windows always use the custom frame - they just have a 300 // Constrained windows always use the custom frame - they just have a
297 // different set of images. 301 // different set of images.
298 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 302 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
299 303
300 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 304 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 container_->CloseWebContentsModalDialog(); 556 container_->CloseWebContentsModalDialog();
553 } 557 }
554 558
555 private: 559 private:
556 ConstrainedWindowViews* container_; // not owned 560 ConstrainedWindowViews* container_; // not owned
557 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); 561 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh);
558 }; 562 };
559 #endif // defined(USE_ASH) 563 #endif // defined(USE_ASH)
560 564
561 ConstrainedWindowViews::ConstrainedWindowViews( 565 ConstrainedWindowViews::ConstrainedWindowViews(
562 content::WebContents* web_contents, 566 gfx::NativeView parent,
567 bool off_the_record,
563 views::WidgetDelegate* widget_delegate) 568 views::WidgetDelegate* widget_delegate)
564 : web_contents_(web_contents), 569 : off_the_record_(off_the_record) {
565 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_(
566 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) {
567 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 570 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
568 params.delegate = widget_delegate; 571 params.delegate = widget_delegate;
569 params.native_widget = native_constrained_window_->AsNativeWidget();
570 params.child = true; 572 params.child = true;
571 573
572 params.parent = web_contents_->GetNativeView(); 574 params.parent = parent;
573 575
574 #if defined(USE_ASH) 576 #if defined(USE_ASH)
575 // Ash window headers can be transparent. 577 // Ash window headers can be transparent.
576 params.transparent = true; 578 params.transparent = true;
577 views::corewm::SetChildWindowVisibilityChangesAnimated(params.parent);
578 // No animations should get performed on the window since that will re-order
579 // the window stack which will then cause many problems.
580 if (params.parent && params.parent->parent()) {
581 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey,
582 true);
583 }
584 #endif 579 #endif
580
585 Init(params); 581 Init(params);
586
587 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
588 WebContentsModalDialogManager::FromWebContents(web_contents_);
589 web_contents_modal_dialog_manager->AddDialog(this);
590 #if defined(USE_ASH)
591 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true);
592 views::corewm::SetModalParent(GetNativeWindow(),
593 web_contents_->GetView()->GetNativeView());
594 #endif
595 } 582 }
596 583
597 ConstrainedWindowViews::~ConstrainedWindowViews() { 584 ConstrainedWindowViews::~ConstrainedWindowViews() {
598 } 585 }
599 586
600 void ConstrainedWindowViews::ShowWebContentsModalDialog() { 587 void ConstrainedWindowViews::ShowWebContentsModalDialog() {
601 Show(); 588 Show();
602 FocusWebContentsModalDialog(); 589 FocusWebContentsModalDialog();
603 } 590 }
604 591
605 void ConstrainedWindowViews::CloseWebContentsModalDialog() { 592 void ConstrainedWindowViews::CloseWebContentsModalDialog() {
606 #if defined(USE_ASH)
607 gfx::NativeView view = web_contents_->GetNativeView();
608 // Allow the parent to animate again.
609 if (view && view->parent())
610 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey);
611 #endif
612 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
613 WebContentsModalDialogManager::FromWebContents(web_contents_);
614 web_contents_modal_dialog_manager->WillClose(this);
615 Close(); 593 Close();
616 } 594 }
617 595
618 void ConstrainedWindowViews::FocusWebContentsModalDialog() { 596 void ConstrainedWindowViews::FocusWebContentsModalDialog() {
619 if (widget_delegate() && widget_delegate()->GetInitiallyFocusedView()) 597 if (widget_delegate() && widget_delegate()->GetInitiallyFocusedView())
620 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); 598 widget_delegate()->GetInitiallyFocusedView()->RequestFocus();
621 #if defined(USE_ASH) 599 #if defined(USE_ASH)
622 // We don't necessarily have a RootWindow yet. 600 // We don't necessarily have a RootWindow yet.
623 if (GetNativeView()->GetRootWindow()) 601 if (GetNativeView()->GetRootWindow())
624 GetNativeView()->Focus(); 602 GetNativeView()->Focus();
625 #endif 603 #endif
626 } 604 }
627 605
628 void ConstrainedWindowViews::PulseWebContentsModalDialog() { 606 void ConstrainedWindowViews::PulseWebContentsModalDialog() {
629 } 607 }
630 608
631 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { 609 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() {
632 return Widget::GetNativeWindow(); 610 return Widget::GetNativeWindow();
633 } 611 }
634 612
613 ConstrainedWindowViews* ConstrainedWindowViews::Create(
614 content::WebContents* web_contents,
615 views::WidgetDelegate* widget_delegate) {
616 WebContentsModalDialogManager* manager =
617 WebContentsModalDialogManager::FromWebContents(web_contents);
618 ConstrainedWindowViews* dialog = new ConstrainedWindowViews(
619 web_contents->GetNativeView(),
620 web_contents->GetBrowserContext()->IsOffTheRecord(),
621 widget_delegate);
622 manager->AddDialog(dialog);
623 return dialog;
624 }
625
635 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { 626 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() {
636 #if defined(USE_ASH) 627 #if defined(USE_ASH)
637 CommandLine* command_line = CommandLine::ForCurrentProcess(); 628 CommandLine* command_line = CommandLine::ForCurrentProcess();
638 if (command_line->HasSwitch(switches::kEnableNewDialogStyle)) 629 if (command_line->HasSwitch(switches::kEnableNewDialogStyle))
639 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this); 630 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(this);
640 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh; 631 ConstrainedWindowFrameViewAsh* frame = new ConstrainedWindowFrameViewAsh;
641 frame->Init(this); 632 frame->Init(this);
642 return frame; 633 return frame;
643 #endif 634 #endif
644 return new ConstrainedWindowFrameView(this); 635 return new ConstrainedWindowFrameView(this, off_the_record_);
645 } 636 }
646
647 void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() {
648 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
649 WebContentsModalDialogManager::FromWebContents(web_contents_);
650 web_contents_modal_dialog_manager->WillClose(this);
651 }
652
653 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() {
654 Activate();
655 }
656
657 views::internal::NativeWidgetDelegate*
658 ConstrainedWindowViews::AsNativeWidgetDelegate() {
659 return this;
660 }
661
662 int ConstrainedWindowViews::GetNonClientComponent(const gfx::Point& point) {
663 // Prevent a constrained window to be moved by the user.
664 return HTNOWHERE;
665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698