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

Unified Diff: chrome/browser/ui/views/extensions/shell_window_views.cc

Issue 10822004: Draggable region support for frameless app window on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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..e4af1287fee02453ace241e6305e78bf986d52ad 100644
--- a/chrome/browser/ui/views/extensions/shell_window_views.cc
+++ b/chrome/browser/ui/views/extensions/shell_window_views.cc
@@ -6,6 +6,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/common/extensions/draggable_region.h"
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.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,12 +197,19 @@ 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;
// Then see if the point is within any of the window controls.
- if (close_button_->visible() &&
+ if (close_button_ && close_button_->visible() &&
close_button_->GetMirroredBounds().Contains(point))
return HTCLOSE;
@@ -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,35 @@ void ShellWindowViews::UpdateWindowTitle() {
window_->UpdateWindowTitle();
}
+void ShellWindowViews::UpdateDraggableRegions(
+ const std::vector<extensions::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<extensions::DraggableRegion>::const_iterator iter =
+ regions.begin();
+ iter != regions.end(); ++iter) {
+ const extensions::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,

Powered by Google App Engine
This is Rietveld 408576698