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

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

Issue 11028125: Remove legacy draggable region code and refactor to share common draggable region code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch 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 | 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/extensions/shell_window_views.h" 5 #include "chrome/browser/ui/views/extensions/shell_window_views.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/favicon/favicon_tab_helper.h" 9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents.h" 10 #include "chrome/browser/ui/tab_contents/tab_contents.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 resize_border, 203 resize_border,
204 resize_border, 204 resize_border,
205 kResizeAreaCornerSize, 205 kResizeAreaCornerSize,
206 kResizeAreaCornerSize, 206 kResizeAreaCornerSize,
207 can_ever_resize); 207 can_ever_resize);
208 if (frame_component != HTNOWHERE) 208 if (frame_component != HTNOWHERE)
209 return frame_component; 209 return frame_component;
210 210
211 // Check for possible draggable region in the client area for the frameless 211 // Check for possible draggable region in the client area for the frameless
212 // window. 212 // window.
213 if (window_->frameless() && 213 if (window_->IsInsideDraggableRegions(point.x(), point.y()))
214 window_->draggable_region() &&
215 window_->draggable_region()->contains(point.x(), point.y()))
216 return HTCAPTION; 214 return HTCAPTION;
217 215
218 int client_component = frame_->client_view()->NonClientHitTest(point); 216 int client_component = frame_->client_view()->NonClientHitTest(point);
219 if (client_component != HTNOWHERE) 217 if (client_component != HTNOWHERE)
220 return client_component; 218 return client_component;
221 219
222 // Then see if the point is within any of the window controls. 220 // Then see if the point is within any of the window controls.
223 if (close_button_ && close_button_->visible() && 221 if (close_button_ && close_button_->visible() &&
224 close_button_->GetMirroredBounds().Contains(point)) 222 close_button_->GetMirroredBounds().Contains(point))
225 return HTCLOSE; 223 return HTCLOSE;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 308
311 void ShellWindowFrameView::ButtonPressed(views::Button* sender, 309 void ShellWindowFrameView::ButtonPressed(views::Button* sender,
312 const ui::Event& event) { 310 const ui::Event& event) {
313 DCHECK(!window_->frameless()); 311 DCHECK(!window_->frameless());
314 if (sender == close_button_) 312 if (sender == close_button_)
315 frame_->Close(); 313 frame_->Close();
316 } 314 }
317 315
318 ShellWindowViews::ShellWindowViews(ShellWindow* shell_window, 316 ShellWindowViews::ShellWindowViews(ShellWindow* shell_window,
319 const ShellWindow::CreateParams& win_params) 317 const ShellWindow::CreateParams& win_params)
320 : shell_window_(shell_window), 318 : NativeShellWindow(win_params),
319 shell_window_(shell_window),
321 web_view_(NULL), 320 web_view_(NULL),
322 is_fullscreen_(false), 321 is_fullscreen_(false) {
323 frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) {
324 window_ = new views::Widget; 322 window_ = new views::Widget;
325 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 323 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
326 params.delegate = this; 324 params.delegate = this;
327 params.remove_standard_frame = true; 325 params.remove_standard_frame = true;
328 params.use_system_default_icon = true; 326 params.use_system_default_icon = true;
329 minimum_size_ = win_params.minimum_size; 327 minimum_size_ = win_params.minimum_size;
330 maximum_size_ = win_params.maximum_size; 328 maximum_size_ = win_params.maximum_size;
331 window_->Init(params); 329 window_->Init(params);
332 gfx::Rect window_bounds = 330 gfx::Rect window_bounds =
333 window_->non_client_view()->GetWindowBoundsForClientBounds( 331 window_->non_client_view()->GetWindowBoundsForClientBounds(
(...skipping 26 matching lines...) Expand all
360 return web_view_; 358 return web_view_;
361 } 359 }
362 360
363 bool ShellWindowViews::ShouldDescendIntoChildForEventHandling( 361 bool ShellWindowViews::ShouldDescendIntoChildForEventHandling(
364 gfx::NativeView child, 362 gfx::NativeView child,
365 const gfx::Point& location) { 363 const gfx::Point& location) {
366 #if defined(USE_AURA) 364 #if defined(USE_AURA)
367 DCHECK_EQ(child, web_view_->web_contents()->GetView()->GetNativeView()); 365 DCHECK_EQ(child, web_view_->web_contents()->GetView()->GetNativeView());
368 // Shell window should claim mouse events that fall within the draggable 366 // Shell window should claim mouse events that fall within the draggable
369 // region. 367 // region.
370 return !draggable_region_.get() || 368 return !IsInsideDraggableRegions(location.x(), location.y());
371 !draggable_region_->contains(location.x(), location.y());
372 #else 369 #else
373 return true; 370 return true;
374 #endif 371 #endif
375 } 372 }
376 373
377 void ShellWindowViews::OnFocus() { 374 void ShellWindowViews::OnFocus() {
378 web_view_->RequestFocus(); 375 web_view_->RequestFocus();
379 } 376 }
380 377
381 void ShellWindowViews::ViewHierarchyChanged( 378 void ShellWindowViews::ViewHierarchyChanged(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 return CanResize(); 499 return CanResize();
503 } 500 }
504 501
505 views::View* ShellWindowViews::GetContentsView() { 502 views::View* ShellWindowViews::GetContentsView() {
506 return this; 503 return this;
507 } 504 }
508 505
509 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView( 506 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView(
510 views::Widget* widget) { 507 views::Widget* widget) {
511 #if defined(USE_ASH) 508 #if defined(USE_ASH)
512 if (!frameless_) { 509 if (!frameless()) {
513 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); 510 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh();
514 frame->Init(widget); 511 frame->Init(widget);
515 return frame; 512 return frame;
516 } 513 }
517 #endif 514 #endif
518 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); 515 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this);
519 frame_view->Init(window_); 516 frame_view->Init(window_);
520 return frame_view; 517 return frame_view;
521 } 518 }
522 519
(...skipping 17 matching lines...) Expand all
540 DCHECK(window_); 537 DCHECK(window_);
541 DCHECK(web_view_); 538 DCHECK(web_view_);
542 gfx::Size sz = web_view_->size(); 539 gfx::Size sz = web_view_->size();
543 int height = sz.height(), width = sz.width(); 540 int height = sz.height(), width = sz.width();
544 int radius = 1; 541 int radius = 1;
545 gfx::Path path; 542 gfx::Path path;
546 if (window_->IsMaximized() || window_->IsFullscreen()) { 543 if (window_->IsMaximized() || window_->IsFullscreen()) {
547 // Don't round the corners when the window is maximized or fullscreen. 544 // Don't round the corners when the window is maximized or fullscreen.
548 path.addRect(0, 0, width, height); 545 path.addRect(0, 0, width, height);
549 } else { 546 } else {
550 if (frameless_) { 547 if (frameless()) {
551 path.moveTo(0, radius); 548 path.moveTo(0, radius);
552 path.lineTo(radius, 0); 549 path.lineTo(radius, 0);
553 path.lineTo(width - radius, 0); 550 path.lineTo(width - radius, 0);
554 path.lineTo(width, radius); 551 path.lineTo(width, radius);
555 } else { 552 } else {
556 // Don't round the top corners in chrome-style frame mode. 553 // Don't round the top corners in chrome-style frame mode.
557 path.moveTo(0, 0); 554 path.moveTo(0, 0);
558 path.lineTo(width, 0); 555 path.lineTo(width, 0);
559 } 556 }
560 path.lineTo(width, height - radius - 1); 557 path.lineTo(width, height - radius - 1);
561 path.lineTo(width - radius - 1, height); 558 path.lineTo(width - radius - 1, height);
562 path.lineTo(radius + 1, height); 559 path.lineTo(radius + 1, height);
563 path.lineTo(0, height - radius - 1); 560 path.lineTo(0, height - radius - 1);
564 path.close(); 561 path.close();
565 } 562 }
566 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1); 563 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1);
567 564
568 SkRegion* rgn = new SkRegion; 565 SkRegion* rgn = new SkRegion;
569 if (!window_->IsFullscreen()) { 566 if (!window_->IsFullscreen()) {
570 if (draggable_region()) 567 if (draggable_regions())
571 rgn->op(*draggable_region(), SkRegion::kUnion_Op); 568 rgn->op(*draggable_regions(), SkRegion::kUnion_Op);
572 if (!window_->IsMaximized()) { 569 if (!window_->IsMaximized()) {
573 if (frameless_) 570 if (frameless())
574 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op); 571 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op);
575 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); 572 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op);
576 rgn->op(width - kResizeInsideBoundsSize, 0, width, height, 573 rgn->op(width - kResizeInsideBoundsSize, 0, width, height,
577 SkRegion::kUnion_Op); 574 SkRegion::kUnion_Op);
578 rgn->op(0, height - kResizeInsideBoundsSize, width, height, 575 rgn->op(0, height - kResizeInsideBoundsSize, width, height,
579 SkRegion::kUnion_Op); 576 SkRegion::kUnion_Op);
580 } 577 }
581 } 578 }
582 if (web_contents()->GetRenderViewHost()->GetView()) 579 if (web_contents()->GetRenderViewHost()->GetView())
583 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); 580 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 window_->UpdateWindowIcon(); 615 window_->UpdateWindowIcon();
619 } 616 }
620 617
621 void ShellWindowViews::UpdateWindowTitle() { 618 void ShellWindowViews::UpdateWindowTitle() {
622 window_->UpdateWindowTitle(); 619 window_->UpdateWindowTitle();
623 } 620 }
624 621
625 void ShellWindowViews::UpdateDraggableRegions( 622 void ShellWindowViews::UpdateDraggableRegions(
626 const std::vector<extensions::DraggableRegion>& regions) { 623 const std::vector<extensions::DraggableRegion>& regions) {
627 // Draggable region is not supported for non-frameless window. 624 // Draggable region is not supported for non-frameless window.
628 if (!frameless_) 625 if (!frameless())
629 return; 626 return;
630 627
631 SkRegion* draggable_region = new SkRegion; 628 NativeShellWindow::UpdateDraggableRegions(regions);
632
633 // By default, the whole window is non-draggable. We need to explicitly
634 // include those draggable regions.
635 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
636 regions.begin();
637 iter != regions.end(); ++iter) {
638 const extensions::DraggableRegion& region = *iter;
639 draggable_region->op(
640 region.bounds.x(),
641 region.bounds.y(),
642 region.bounds.right(),
643 region.bounds.bottom(),
644 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
645 }
646
647 draggable_region_.reset(draggable_region);
648 OnViewWasResized(); 629 OnViewWasResized();
649 } 630 }
650 631
651 void ShellWindowViews::UpdateLegacyDraggableRegions(
652 const std::vector<extensions::DraggableRegion>& regions) {
653 // Draggable region is not supported for non-frameless window.
654 if (!frameless_)
655 return;
656
657 SkRegion* draggable_region = new SkRegion;
658
659 // By default, the whole window is draggable.
660 gfx::Rect bounds = GetBounds();
661 draggable_region->op(0, 0, bounds.right(), bounds.bottom(),
662 SkRegion::kUnion_Op);
663
664 // Exclude those desinated as non-draggable.
665 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
666 regions.begin();
667 iter != regions.end(); ++iter) {
668 const extensions::DraggableRegion& region = *iter;
669 draggable_region->op(region.bounds.x(),
670 region.bounds.y(),
671 region.bounds.right(),
672 region.bounds.bottom(),
673 SkRegion::kDifference_Op);
674 }
675
676 draggable_region_.reset(draggable_region);
677 OnViewWasResized();
678 }
679
680 void ShellWindowViews::HandleKeyboardEvent( 632 void ShellWindowViews::HandleKeyboardEvent(
681 const content::NativeWebKeyboardEvent& event) { 633 const content::NativeWebKeyboardEvent& event) {
682 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, 634 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
683 GetFocusManager()); 635 GetFocusManager());
684 } 636 }
685 637
686 void ShellWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, 638 void ShellWindowViews::SaveWindowPlacement(const gfx::Rect& bounds,
687 ui::WindowShowState show_state) { 639 ui::WindowShowState show_state) {
688 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); 640 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state);
689 shell_window_->SaveWindowPosition(); 641 shell_window_->SaveWindowPosition();
690 } 642 }
691 643
692 // static 644 // static
693 NativeShellWindow* NativeShellWindow::Create( 645 NativeShellWindow* NativeShellWindow::Create(
694 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { 646 ShellWindow* shell_window, const ShellWindow::CreateParams& params) {
695 return new ShellWindowViews(shell_window, params); 647 return new ShellWindowViews(shell_window, params);
696 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698