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

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: fix Android link error Created 7 years, 10 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources); 163 DISALLOW_COPY_AND_ASSIGN(VistaWindowResources);
164 }; 164 };
165 165
166 gfx::ImageSkia* XPWindowResources::images_[]; 166 gfx::ImageSkia* XPWindowResources::images_[];
167 gfx::ImageSkia* VistaWindowResources::images_[]; 167 gfx::ImageSkia* VistaWindowResources::images_[];
168 168
169 class ConstrainedWindowFrameView : public views::NonClientFrameView, 169 class ConstrainedWindowFrameView : public views::NonClientFrameView,
170 public views::ButtonListener { 170 public views::ButtonListener {
171 public: 171 public:
172 explicit ConstrainedWindowFrameView(ConstrainedWindowViews* container); 172 ConstrainedWindowFrameView(ConstrainedWindowViews* container,
173 bool browser_is_off_the_record);
173 virtual ~ConstrainedWindowFrameView(); 174 virtual ~ConstrainedWindowFrameView();
174 175
175 void UpdateWindowTitle(); 176 void UpdateWindowTitle();
176 177
177 // Overridden from views::NonClientFrameView: 178 // Overridden from views::NonClientFrameView:
178 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; 179 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
179 virtual gfx::Rect GetWindowBoundsForClientBounds( 180 virtual gfx::Rect GetWindowBoundsForClientBounds(
180 const gfx::Rect& client_bounds) const OVERRIDE; 181 const gfx::Rect& client_bounds) const OVERRIDE;
181 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; 182 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
182 virtual void GetWindowMask(const gfx::Size& size, 183 virtual void GetWindowMask(const gfx::Size& size,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 void PaintClientEdge(gfx::Canvas* canvas); 219 void PaintClientEdge(gfx::Canvas* canvas);
219 220
220 // Layout various sub-components of this view. 221 // Layout various sub-components of this view.
221 void LayoutWindowControls(); 222 void LayoutWindowControls();
222 void LayoutTitleBar(); 223 void LayoutTitleBar();
223 224
224 // Returns the bounds of the client area for the specified view size. 225 // Returns the bounds of the client area for the specified view size.
225 gfx::Rect CalculateClientAreaBounds(int width, int height) const; 226 gfx::Rect CalculateClientAreaBounds(int width, int height) const;
226 227
227 SkColor GetTitleColor() const { 228 SkColor GetTitleColor() const {
228 return container_->owner()->GetBrowserContext()->IsOffTheRecord() 229 return browser_is_off_the_record_
229 #if defined(OS_WIN) && !defined(USE_AURA) 230 #if defined(OS_WIN) && !defined(USE_AURA)
230 || !ui::win::IsAeroGlassEnabled() 231 || !ui::win::IsAeroGlassEnabled()
231 #endif 232 #endif
232 ? SK_ColorWHITE : SK_ColorBLACK; 233 ? SK_ColorWHITE : SK_ColorBLACK;
233 } 234 }
234 235
235 // Loads the appropriate set of WindowResources for the frame view. 236 // Loads the appropriate set of WindowResources for the frame view.
236 void InitWindowResources(); 237 void InitWindowResources();
237 238
238 ConstrainedWindowViews* container_; 239 ConstrainedWindowViews* container_;
239 240
241 bool browser_is_off_the_record_;
242
240 scoped_ptr<views::WindowResources> resources_; 243 scoped_ptr<views::WindowResources> resources_;
241 244
242 gfx::Rect title_bounds_; 245 gfx::Rect title_bounds_;
243 246
244 views::ImageButton* close_button_; 247 views::ImageButton* close_button_;
245 248
246 // The bounds of the ClientView. 249 // The bounds of the ClientView.
247 gfx::Rect client_view_bounds_; 250 gfx::Rect client_view_bounds_;
248 251
249 // Background painter for the frame. 252 // Background painter for the frame.
(...skipping 29 matching lines...) Expand all
279 // The title text starts 2 px from the right edge of the left frame border. 282 // The title text starts 2 px from the right edge of the left frame border.
280 const int kTitleLeftSpacing = 2; 283 const int kTitleLeftSpacing = 2;
281 // There is a 5 px gap between the title text and the caption buttons. 284 // There is a 5 px gap between the title text and the caption buttons.
282 const int kTitleCaptionSpacing = 5; 285 const int kTitleCaptionSpacing = 5;
283 286
284 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); 287 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0);
285 288
286 } // namespace 289 } // namespace
287 290
288 ConstrainedWindowFrameView::ConstrainedWindowFrameView( 291 ConstrainedWindowFrameView::ConstrainedWindowFrameView(
289 ConstrainedWindowViews* container) 292 ConstrainedWindowViews* container, bool browser_is_off_the_record)
290 : NonClientFrameView(), 293 : NonClientFrameView(),
291 container_(container), 294 container_(container),
295 browser_is_off_the_record_(browser_is_off_the_record),
292 close_button_(new views::ImageButton(this)), 296 close_button_(new views::ImageButton(this)),
293 frame_background_(new views::FrameBackground()) { 297 frame_background_(new views::FrameBackground()) {
294 InitClass(); 298 InitClass();
295 InitWindowResources(); 299 InitWindowResources();
296 300
297 // Constrained windows always use the custom frame - they just have a 301 // Constrained windows always use the custom frame - they just have a
298 // different set of images. 302 // different set of images.
299 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 303 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
300 304
301 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 305 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 container_->CloseWebContentsModalDialog(); 557 container_->CloseWebContentsModalDialog();
554 } 558 }
555 559
556 private: 560 private:
557 ConstrainedWindowViews* container_; // not owned 561 ConstrainedWindowViews* container_; // not owned
558 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh); 562 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameViewAsh);
559 }; 563 };
560 #endif // defined(USE_ASH) 564 #endif // defined(USE_ASH)
561 565
562 ConstrainedWindowViews::ConstrainedWindowViews( 566 ConstrainedWindowViews::ConstrainedWindowViews(
563 content::WebContents* web_contents, 567 gfx::NativeView parent,
568 bool off_the_record,
564 views::WidgetDelegate* widget_delegate) 569 views::WidgetDelegate* widget_delegate)
565 : web_contents_(web_contents), 570 : off_the_record_(off_the_record) {
566 ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_(
567 NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) {
568 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 571 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
569 params.delegate = widget_delegate; 572 params.delegate = widget_delegate;
570 params.native_widget = native_constrained_window_->AsNativeWidget();
571 params.child = true; 573 params.child = true;
572 574
573 params.parent = web_contents_->GetNativeView(); 575 params.parent = parent;
574 576
575 #if defined(USE_ASH) 577 #if defined(USE_ASH)
576 // Ash window headers can be transparent. 578 // Ash window headers can be transparent.
577 params.transparent = true; 579 params.transparent = true;
578 views::corewm::SetChildWindowVisibilityChangesAnimated(params.parent);
579 // No animations should get performed on the window since that will re-order
580 // the window stack which will then cause many problems.
581 if (params.parent && params.parent->parent()) {
582 params.parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey,
583 true);
584 }
585 #endif 580 #endif
581
586 Init(params); 582 Init(params);
587
588 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
589 WebContentsModalDialogManager::FromWebContents(web_contents_);
590 web_contents_modal_dialog_manager->AddDialog(this);
591 #if defined(USE_ASH)
592 GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true);
593 views::corewm::SetModalParent(GetNativeWindow(),
594 web_contents_->GetView()->GetNativeView());
595 #endif
596 } 583 }
597 584
598 ConstrainedWindowViews::~ConstrainedWindowViews() { 585 ConstrainedWindowViews::~ConstrainedWindowViews() {
599 } 586 }
600 587
601 void ConstrainedWindowViews::ShowWebContentsModalDialog() { 588 void ConstrainedWindowViews::ShowWebContentsModalDialog() {
602 Show(); 589 Show();
603 FocusWebContentsModalDialog(); 590 FocusWebContentsModalDialog();
604 } 591 }
605 592
606 void ConstrainedWindowViews::CloseWebContentsModalDialog() { 593 void ConstrainedWindowViews::CloseWebContentsModalDialog() {
607 #if defined(USE_ASH)
608 gfx::NativeView view = web_contents_->GetNativeView();
609 // Allow the parent to animate again.
610 if (view && view->parent())
611 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey);
612 #endif
613 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
614 WebContentsModalDialogManager::FromWebContents(web_contents_);
615 web_contents_modal_dialog_manager->WillClose(this);
616 Close(); 594 Close();
617 } 595 }
618 596
619 void ConstrainedWindowViews::FocusWebContentsModalDialog() { 597 void ConstrainedWindowViews::FocusWebContentsModalDialog() {
620 if (widget_delegate() && widget_delegate()->GetInitiallyFocusedView()) 598 if (widget_delegate() && widget_delegate()->GetInitiallyFocusedView())
621 widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); 599 widget_delegate()->GetInitiallyFocusedView()->RequestFocus();
622 #if defined(USE_ASH) 600 #if defined(USE_ASH)
623 // We don't necessarily have a RootWindow yet. 601 // We don't necessarily have a RootWindow yet.
624 if (GetNativeView()->GetRootWindow()) 602 if (GetNativeView()->GetRootWindow())
625 GetNativeView()->Focus(); 603 GetNativeView()->Focus();
626 #endif 604 #endif
627 } 605 }
628 606
629 void ConstrainedWindowViews::PulseWebContentsModalDialog() { 607 void ConstrainedWindowViews::PulseWebContentsModalDialog() {
630 } 608 }
631 609
632 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() { 610 gfx::NativeWindow ConstrainedWindowViews::GetNativeWindow() {
633 return Widget::GetNativeWindow(); 611 return Widget::GetNativeWindow();
634 } 612 }
635 613
614 ConstrainedWindowViews* ConstrainedWindowViews::Create(
615 content::WebContents* web_contents,
616 views::WidgetDelegate* widget_delegate) {
617 WebContentsModalDialogManager* manager =
618 WebContentsModalDialogManager::FromWebContents(web_contents);
619 ConstrainedWindowViews* dialog = new ConstrainedWindowViews(
620 web_contents->GetNativeView(),
621 web_contents->GetBrowserContext()->IsOffTheRecord(),
622 widget_delegate);
623 manager->AddDialog(dialog);
624 return dialog;
625 }
626
636 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() { 627 views::NonClientFrameView* ConstrainedWindowViews::CreateNonClientFrameView() {
637 if (views::DialogDelegate::UseNewStyle()) 628 if (views::DialogDelegate::UseNewStyle())
638 return new views::DialogFrameView(widget_delegate()->GetWindowTitle()); 629 return new views::DialogFrameView(widget_delegate()->GetWindowTitle());
639 #if defined(USE_ASH) 630 #if defined(USE_ASH)
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
« no previous file with comments | « chrome/browser/ui/views/constrained_window_views.h ('k') | chrome/browser/ui/views/constrained_window_views_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698