Chromium Code Reviews| Index: chrome/browser/ui/views/extensions/shell_window_views.cc |
| diff --git a/chrome/browser/ui/views/extensions/shell_window_views.cc b/chrome/browser/ui/views/extensions/shell_window_views.cc |
| index a0c44a1fce22f18c04fee092a56d91ec11ee2711..da183e9b82294989fc9c7cc4dd7f9c4618cd069d 100644 |
| --- a/chrome/browser/ui/views/extensions/shell_window_views.cc |
| +++ b/chrome/browser/ui/views/extensions/shell_window_views.cc |
| @@ -11,6 +11,7 @@ |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_contents_view.h" |
| +#include "content/public/common/draggable_region.h" |
| #include "grit/ui_resources.h" |
| #include "grit/ui_strings.h" // Accessibility names |
| #include "third_party/skia/include/core/SkPaint.h" |
| @@ -20,7 +21,6 @@ |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/image/image.h" |
| #include "ui/gfx/path.h" |
| -#include "ui/gfx/scoped_sk_region.h" |
| #include "ui/views/controls/button/button.h" |
| #include "ui/views/controls/button/image_button.h" |
| #include "ui/views/controls/webview/webview.h" |
| @@ -63,7 +63,7 @@ class ShellWindowFrameView : public views::NonClientFrameView, |
| public: |
| static const char kViewClassName[]; |
| - explicit ShellWindowFrameView(bool frameless); |
| + explicit ShellWindowFrameView(ShellWindowViews* window); |
| virtual ~ShellWindowFrameView(); |
| void Init(views::Widget* frame); |
| @@ -91,21 +91,19 @@ class ShellWindowFrameView : public views::NonClientFrameView, |
| virtual void ButtonPressed(views::Button* sender, const views::Event& event) |
| OVERRIDE; |
| + ShellWindowViews* window_; |
| views::Widget* frame_; |
| views::ImageButton* close_button_; |
| - bool is_frameless_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView); |
| }; |
| const char ShellWindowFrameView::kViewClassName[] = |
| "browser/ui/views/extensions/ShellWindowFrameView"; |
| -ShellWindowFrameView::ShellWindowFrameView(bool frameless) |
| - : frame_(NULL), |
| - close_button_(NULL), |
| - is_frameless_(frameless) { |
| +ShellWindowFrameView::ShellWindowFrameView(ShellWindowViews* window) |
| + : window_(window), |
| + close_button_(NULL) { |
| } |
| ShellWindowFrameView::~ShellWindowFrameView() { |
| @@ -114,7 +112,7 @@ ShellWindowFrameView::~ShellWindowFrameView() { |
| void ShellWindowFrameView::Init(views::Widget* frame) { |
| frame_ = frame; |
| - if (!is_frameless_) { |
| + if (!window_->frameless()) { |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| close_button_ = new views::ImageButton(this); |
| close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| @@ -146,7 +144,7 @@ void ShellWindowFrameView::Init(views::Widget* frame) { |
| } |
| gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { |
| - if (is_frameless_ || frame_->IsFullscreen()) |
| + if (window_->frameless() || frame_->IsFullscreen()) |
| return bounds(); |
| return gfx::Rect(0, kCaptionHeight, width(), |
| std::max(0, height() - kCaptionHeight)); |
| @@ -154,7 +152,7 @@ gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { |
| gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( |
| const gfx::Rect& client_bounds) const { |
| - if (is_frameless_) |
| + if (window_->frameless()) |
| return client_bounds; |
| int closeButtonOffsetX = |
| @@ -199,6 +197,13 @@ int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) { |
| if (frame_component != HTNOWHERE) |
| return frame_component; |
| + // Check for possible draggable region in the client area for the frameless |
| + // window. |
| + if (window_->frameless() && |
| + window_->draggable_region() && |
| + window_->draggable_region()->contains(point.x(), point.y())) |
| + return HTCAPTION; |
| + |
| int client_component = frame_->client_view()->NonClientHitTest(point); |
| if (client_component != HTNOWHERE) |
| return client_component; |
| @@ -225,7 +230,7 @@ gfx::Size ShellWindowFrameView::GetPreferredSize() { |
| } |
| void ShellWindowFrameView::Layout() { |
| - if (is_frameless_) |
| + if (window_->frameless()) |
| return; |
| gfx::Size close_size = close_button_->GetPreferredSize(); |
| int closeButtonOffsetY = |
| @@ -239,7 +244,7 @@ void ShellWindowFrameView::Layout() { |
| } |
| void ShellWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
| - if (is_frameless_) |
| + if (window_->frameless()) |
| return; |
| // TODO(jeremya): different look for inactive? |
| SkPaint paint; |
| @@ -264,7 +269,7 @@ std::string ShellWindowFrameView::GetClassName() const { |
| gfx::Size ShellWindowFrameView::GetMinimumSize() { |
| gfx::Size min_size = frame_->client_view()->GetMinimumSize(); |
| - if (is_frameless_) |
| + if (window_->frameless()) |
| return min_size; |
| // Ensure we can display the top of the caption area. |
| @@ -282,7 +287,7 @@ gfx::Size ShellWindowFrameView::GetMinimumSize() { |
| gfx::Size ShellWindowFrameView::GetMaximumSize() { |
| gfx::Size max_size = frame_->client_view()->GetMaximumSize(); |
| - if (is_frameless_) |
| + if (window_->frameless()) |
| return max_size; |
| if (!max_size.IsEmpty()) { |
| @@ -294,7 +299,7 @@ gfx::Size ShellWindowFrameView::GetMaximumSize() { |
| void ShellWindowFrameView::ButtonPressed(views::Button* sender, |
| const views::Event& event) { |
| - DCHECK(!is_frameless_); |
| + DCHECK(!window_->frameless()); |
| if (sender == close_button_) |
| frame_->Close(); |
| } |
| @@ -306,8 +311,7 @@ ShellWindowViews::ShellWindowViews(Profile* profile, |
| : ShellWindow(profile, extension, url), |
| web_view_(NULL), |
| is_fullscreen_(false), |
| - use_custom_frame_( |
| - win_params.frame == ShellWindow::CreateParams::FRAME_NONE) { |
| + frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) { |
| window_ = new views::Widget; |
| views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| params.delegate = this; |
| @@ -444,11 +448,6 @@ void ShellWindowViews::SetBounds(const gfx::Rect& bounds) { |
| GetWidget()->SetBounds(bounds); |
| } |
| -void ShellWindowViews::SetDraggableRegion(SkRegion* region) { |
| - caption_region_.Set(region); |
| - OnViewWasResized(); |
| -} |
| - |
| void ShellWindowViews::FlashFrame(bool flash) { |
| window_->FlashFrame(flash); |
| } |
| @@ -475,8 +474,7 @@ views::View* ShellWindowViews::GetContentsView() { |
| views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView( |
| views::Widget* widget) { |
| - ShellWindowFrameView* frame_view = |
| - new ShellWindowFrameView(use_custom_frame_); |
| + ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); |
| frame_view->Init(window_); |
| return frame_view; |
| } |
| @@ -508,7 +506,7 @@ void ShellWindowViews::OnViewWasResized() { |
| // Don't round the corners when the window is maximized or fullscreen. |
| path.addRect(0, 0, width, height); |
| } else { |
| - if (use_custom_frame_) { |
| + if (frameless_) { |
| path.moveTo(0, radius); |
| path.lineTo(radius, 0); |
| path.lineTo(width - radius, 0); |
| @@ -528,10 +526,10 @@ void ShellWindowViews::OnViewWasResized() { |
| SkRegion* rgn = new SkRegion; |
| if (!window_->IsFullscreen()) { |
| - if (caption_region_.Get()) |
| - rgn->op(*caption_region_.Get(), SkRegion::kUnion_Op); |
| + if (draggable_region_.Get()) |
| + rgn->op(*draggable_region_.Get(), SkRegion::kUnion_Op); |
| if (!window_->IsMaximized()) { |
| - if (use_custom_frame_) |
| + if (frameless_) |
| rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op); |
| rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); |
| rgn->op(width - kResizeInsideBoundsSize, 0, width, height, |
| @@ -554,6 +552,36 @@ void ShellWindowViews::UpdateWindowTitle() { |
| window_->UpdateWindowTitle(); |
| } |
| + |
|
jeremya
2012/08/07 01:00:17
nit: only 1 empty line here
jianli
2012/08/07 20:38:06
Done.
|
| +void ShellWindowViews::UpdateDraggableRegions( |
| + const std::vector<content::DraggableRegion>& regions) { |
| + // Draggable region is not supported for non-frameless window. |
| + if (!frameless_) |
| + return; |
| + |
| + SkRegion* draggable_region = new SkRegion; |
| + |
| + // By default, the whole window is draggable. |
| + gfx::Rect bounds = GetBounds(); |
| + draggable_region->op(0, 0, bounds.right(), bounds.bottom(), |
| + SkRegion::kUnion_Op); |
| + |
| + // Exclude those desinated as non-draggable. |
| + for (std::vector<content::DraggableRegion>::const_iterator iter = |
| + regions.begin(); |
| + iter != regions.end(); ++iter) { |
| + const content::DraggableRegion& region = *iter; |
| + draggable_region->op(region.bounds.x(), |
| + region.bounds.y(), |
| + region.bounds.right(), |
| + region.bounds.bottom(), |
| + SkRegion::kDifference_Op); |
| + } |
| + |
| + draggable_region_.Set(draggable_region); |
| + OnViewWasResized(); |
| +} |
| + |
| // static |
| ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| const extensions::Extension* extension, |