diff options
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/blocked_popup_container_view_views.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host.cc | 114 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host_gtk.cc | 15 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host_win.cc | 111 | ||||
-rw-r--r-- | chrome/browser/views/notifications/balloon_view.cc | 2 |
7 files changed, 124 insertions, 123 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 5d78ec4..419e0bb 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -857,7 +857,7 @@ void AutocompletePopupContentsView::UpdateBlurRegion() { gfx::Path contents_path; MakeContentsPath(&contents_path, contents_rect); ScopedGDIObject<HRGN> popup_region; - popup_region.Set(contents_path.CreateHRGN()); + popup_region.Set(contents_path.CreateNativeRegion()); bb.hRgnBlur = popup_region.Get(); DwmEnableBlurBehindWindow(GetWidget()->GetNativeView(), &bb); #endif diff --git a/chrome/browser/views/blocked_popup_container_view_views.cc b/chrome/browser/views/blocked_popup_container_view_views.cc index 832447e..4a47eb0 100644 --- a/chrome/browser/views/blocked_popup_container_view_views.cc +++ b/chrome/browser/views/blocked_popup_container_view_views.cc @@ -570,5 +570,5 @@ void BlockedPopupContainerViewViews::UpdateWidgetShape( rect.set(0, 0, SkIntToScalar(size.width()), SkIntToScalar(size.height())); gfx::Path path; path.addRoundRect(rect, kRoundedCornerRad, SkPath::kCW_Direction); - widget->SetShape(path); + widget->SetShape(path.CreateNativeRegion()); } diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc index 46888af..1f53cd2 100644 --- a/chrome/browser/views/find_bar_host.cc +++ b/chrome/browser/views/find_bar_host.cc @@ -4,8 +4,10 @@ #include "chrome/browser/views/find_bar_host.h" +#include "app/gfx/path.h" #include "app/slide_animation.h" #include "base/keyboard_codes.h" +#include "base/scoped_handle.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/find_bar_controller.h" @@ -23,6 +25,8 @@ // static bool FindBarHost::disable_animations_during_testing_ = false; +using gfx::Path; + namespace browser { // Declared in browser_dialogs.h so others don't have to depend on our header. @@ -252,6 +256,116 @@ void FindBarHost::GetDialogBounds(gfx::Rect* bounds) { *bounds = browser_view_->GetFindBarBoundingBox(); } +void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) { + // |w| is used to make it easier to create the part of the polygon that curves + // the right side of the Find window. It essentially keeps track of the + // x-pixel position of the right-most background image inside the view. + // TODO(finnur): Let the view tell us how to draw the curves or convert + // this to a CustomFrameWindow. + int w = new_pos.width() - 6; // -6 positions us at the left edge of the + // rightmost background image of the view. + + // This polygon array represents the outline of the background image for the + // dialog. Basically, it encompasses only the visible pixels of the + // concatenated find_dlg_LMR_bg images (where LMR = [left | middle | right]). + static const Path::Point polygon[] = { + {0, 0}, {0, 1}, {2, 3}, {2, 29}, {4, 31}, + {4, 32}, {w+0, 32}, + {w+0, 31}, {w+1, 31}, {w+3, 29}, {w+3, 3}, {w+6, 0} + }; + + // Find the largest x and y value in the polygon. + int max_x = 0, max_y = 0; + for (size_t i = 0; i < arraysize(polygon); i++) { + max_x = std::max(max_x, static_cast<int>(polygon[i].x)); + max_y = std::max(max_y, static_cast<int>(polygon[i].y)); + } + + // We then create the polygon and use SetWindowRgn to force the window to draw + // only within that area. This region may get reduced in size below. + Path path(polygon, arraysize(polygon)); + ScopedRegion region(path.CreateNativeRegion()); + + // Are we animating? + if (find_dialog_animation_offset_ > 0) { + // The animation happens in two steps: First, we clip the window and then in + // GetDialogPosition we offset the window position so that it still looks + // attached to the toolbar as it grows. We clip the window by creating a + // rectangle region (that gradually increases as the animation progresses) + // and find the intersection between the two regions using CombineRgn. + + // |y| shrinks as the animation progresses from the height of the view down + // to 0 (and reverses when closing). + int y = find_dialog_animation_offset_; + // |y| shrinking means the animation (visible) region gets larger. In other + // words: the rectangle grows upward (when the dialog is opening). + Path animation_path; + SkRect animation_rect = { SkIntToScalar(0), SkIntToScalar(y), + SkIntToScalar(max_x), SkIntToScalar(max_y) }; + animation_path.addRect(animation_rect); + ScopedRegion animation_region(animation_path.CreateNativeRegion()); + region.Set(Path::IntersectRegions(animation_region.Get(), region.Get())); + + // Next, we need to increase the region a little bit to account for the + // curved edges that the view will draw to make it look like grows out of + // the toolbar. + Path::Point left_curve[] = { + {0, y+0}, {0, y+1}, {2, y+3}, {2, y+0}, {0, y+0} + }; + Path::Point right_curve[] = { + {w+3, y+3}, {w+6, y+0}, {w+3, y+0}, {w+3, y+3} + }; + + // Combine the region for the curve on the left with our main region. + Path left_path(left_curve, arraysize(left_curve)); + ScopedRegion r(left_path.CreateNativeRegion()); + region.Set(Path::CombineRegions(r.Get(), region.Get())); + + // Combine the region for the curve on the right with our main region. + Path right_path(right_curve, arraysize(right_curve)); + region.Set(Path::CombineRegions(r.Get(), region.Get())); + } + + // Now see if we need to truncate the region because parts of it obscures + // the main window border. + gfx::Rect dialog_bounds; + GetDialogBounds(&dialog_bounds); + + // Calculate how much our current position overlaps our boundaries. If we + // overlap, it means we have too little space to draw the whole dialog and + // we allow overwriting the scrollbar before we start truncating our dialog. + // + // TODO(brettw) this constant is evil. This is the amount of room we've added + // to the window size, when we set the region, it can change the size. + static const int kAddedWidth = 7; + int difference = (new_pos.right() - kAddedWidth) - + dialog_bounds.width() - + views::NativeScrollBar::GetVerticalScrollBarWidth() + + 1; + if (difference > 0) { + Path::Point exclude[4]; + exclude[0].x = max_x - difference; // Top left corner. + exclude[0].y = 0; + + exclude[1].x = max_x; // Top right corner. + exclude[1].y = 0; + + exclude[2].x = max_x; // Bottom right corner. + exclude[2].y = max_y; + + exclude[3].x = max_x - difference; // Bottom left corner. + exclude[3].y = max_y; + + // Subtract this region from the original region. + gfx::Path exclude_path(exclude, arraysize(exclude)); + ScopedRegion exclude_region(exclude_path.CreateNativeRegion()); + region.Set(Path::SubtractRegion(region.Get(), exclude_region.Get())); + } + + // Window takes ownership of the region. + host_->SetShape(region.release()); +} + gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { // Find the area we have to work with (after accounting for scrollbars, etc). gfx::Rect dialog_bounds; diff --git a/chrome/browser/views/find_bar_host.h b/chrome/browser/views/find_bar_host.h index a67b714..4ccc57a 100644 --- a/chrome/browser/views/find_bar_host.h +++ b/chrome/browser/views/find_bar_host.h @@ -132,7 +132,6 @@ class FindBarHost : public views::AcceleratorTarget, // to prevent from drawing onto Chrome's window border. void UpdateWindowEdges(const gfx::Rect& new_pos); - // Registers this class as the handler for when Escape is pressed. We will // unregister once we loose focus. See also: SetFocusChangeListener(). void RegisterEscAccelerator(); diff --git a/chrome/browser/views/find_bar_host_gtk.cc b/chrome/browser/views/find_bar_host_gtk.cc index e517407..e4a46a2 100644 --- a/chrome/browser/views/find_bar_host_gtk.cc +++ b/chrome/browser/views/find_bar_host_gtk.cc @@ -10,14 +10,9 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/frame/browser_view.h" +#include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h" #include "views/widget/widget_gtk.h" -void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) { - // TODO(davemoore) move the windows implementation to CustomFrameWindow so we - // don't have to implement it for gtk - NOTIMPLEMENTED(); -} - void FindBarHost::AudibleAlert() { // TODO(davemoore) implement NOTIMPLEMENTED(); @@ -37,8 +32,12 @@ void FindBarHost::SetDialogPositionNative(const gfx::Rect& new_pos, } void FindBarHost::GetDialogPositionNative(gfx::Rect* avoid_overlapping_rect) { - // TODO(davemoore) implement - NOTIMPLEMENTED(); + gfx::Rect frame_rect, webcontents_rect; + host_->GetRootWidget()->GetBounds(&frame_rect, true); + TabContentsView* tab_view = find_bar_controller_->tab_contents()->view(); + static_cast<TabContentsViewGtk*>(tab_view)->GetBounds(&webcontents_rect, + true); + avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y()); } diff --git a/chrome/browser/views/find_bar_host_win.cc b/chrome/browser/views/find_bar_host_win.cc index 8ba3c53..7d41f2f 100644 --- a/chrome/browser/views/find_bar_host_win.cc +++ b/chrome/browser/views/find_bar_host_win.cc @@ -12,117 +12,6 @@ #include "views/controls/scrollbar/native_scroll_bar.h" #include "views/widget/widget_win.h" -// TODO(brettw) this should not be so complicated. The view should really be in -// charge of these regions. CustomFrameWindow will do this for us. It will also -// let us set a path for the window region which will avoid some logic here. -void FindBarHost::UpdateWindowEdges(const gfx::Rect& new_pos) { - // |w| is used to make it easier to create the part of the polygon that curves - // the right side of the Find window. It essentially keeps track of the - // x-pixel position of the right-most background image inside the view. - // TODO(finnur): Let the view tell us how to draw the curves or convert - // this to a CustomFrameWindow. - int w = new_pos.width() - 6; // -6 positions us at the left edge of the - // rightmost background image of the view. - - // This polygon array represents the outline of the background image for the - // dialog. Basically, it encompasses only the visible pixels of the - // concatenated find_dlg_LMR_bg images (where LMR = [left | middle | right]). - static const POINT polygon[] = { - {0, 0}, {0, 1}, {2, 3}, {2, 29}, {4, 31}, - {4, 32}, {w+0, 32}, - {w+0, 31}, {w+1, 31}, {w+3, 29}, {w+3, 3}, {w+6, 0} - }; - - // Find the largest x and y value in the polygon. - int max_x = 0, max_y = 0; - for (int i = 0; i < arraysize(polygon); i++) { - max_x = std::max(max_x, static_cast<int>(polygon[i].x)); - max_y = std::max(max_y, static_cast<int>(polygon[i].y)); - } - - // We then create the polygon and use SetWindowRgn to force the window to draw - // only within that area. This region may get reduced in size below. - HRGN region = CreatePolygonRgn(polygon, arraysize(polygon), ALTERNATE); - - // Are we animating? - if (find_dialog_animation_offset_ > 0) { - // The animation happens in two steps: First, we clip the window and then in - // GetDialogPosition we offset the window position so that it still looks - // attached to the toolbar as it grows. We clip the window by creating a - // rectangle region (that gradually increases as the animation progresses) - // and find the intersection between the two regions using CombineRgn. - - // |y| shrinks as the animation progresses from the height of the view down - // to 0 (and reverses when closing). - int y = find_dialog_animation_offset_; - // |y| shrinking means the animation (visible) region gets larger. In other - // words: the rectangle grows upward (when the dialog is opening). - HRGN animation_region = CreateRectRgn(0, y, max_x, max_y); - // |region| will contain the intersected parts after calling this function: - CombineRgn(region, animation_region, region, RGN_AND); - DeleteObject(animation_region); - - // Next, we need to increase the region a little bit to account for the - // curved edges that the view will draw to make it look like grows out of - // the toolbar. - POINT left_curve[] = { - {0, y+0}, {0, y+1}, {2, y+3}, {2, y+0}, {0, y+0} - }; - POINT right_curve[] = { - {w+3, y+3}, {w+6, y+0}, {w+3, y+0}, {w+3, y+3} - }; - - // Combine the region for the curve on the left with our main region. - HRGN r = CreatePolygonRgn(left_curve, arraysize(left_curve), ALTERNATE); - CombineRgn(region, r, region, RGN_OR); - DeleteObject(r); - - // Combine the region for the curve on the right with our main region. - r = CreatePolygonRgn(right_curve, arraysize(right_curve), ALTERNATE); - CombineRgn(region, r, region, RGN_OR); - DeleteObject(r); - } - - // Now see if we need to truncate the region because parts of it obscures - // the main window border. - gfx::Rect dialog_bounds; - GetDialogBounds(&dialog_bounds); - - // Calculate how much our current position overlaps our boundaries. If we - // overlap, it means we have too little space to draw the whole dialog and - // we allow overwriting the scrollbar before we start truncating our dialog. - // - // TODO(brettw) this constant is evil. This is the amount of room we've added - // to the window size, when we set the region, it can change the size. - static const int kAddedWidth = 7; - int difference = (new_pos.right() - kAddedWidth) - - dialog_bounds.width() - - views::NativeScrollBar::GetVerticalScrollBarWidth() + - 1; - if (difference > 0) { - POINT exclude[4] = {0}; - exclude[0].x = max_x - difference; // Top left corner. - exclude[0].y = 0; - - exclude[1].x = max_x; // Top right corner. - exclude[1].y = 0; - - exclude[2].x = max_x; // Bottom right corner. - exclude[2].y = max_y; - - exclude[3].x = max_x - difference; // Bottom left corner. - exclude[3].y = max_y; - - // Subtract this region from the original region. - HRGN exclude_rgn = CreatePolygonRgn(exclude, arraysize(exclude), ALTERNATE); - int result = CombineRgn(region, region, exclude_rgn, RGN_DIFF); - DeleteObject(exclude_rgn); - } - - // The system now owns the region, so we do not delete it. - ::SetWindowRgn(host_->GetNativeView(), region, TRUE); // TRUE = Redraw. -} - NativeWebKeyboardEvent FindBarHost::GetKeyboardEvent( const TabContents* contents, const views::Textfield::Keystroke& key_stroke) { diff --git a/chrome/browser/views/notifications/balloon_view.cc b/chrome/browser/views/notifications/balloon_view.cc index a092ce4..cb0ef1e 100644 --- a/chrome/browser/views/notifications/balloon_view.cc +++ b/chrome/browser/views/notifications/balloon_view.cc @@ -137,7 +137,7 @@ void BalloonViewImpl::SizeContentsWindow() { gfx::Path path; GetContentsMask(contents_rect, &path); - html_container_->SetShape(path); + html_container_->SetShape(path.CreateNativeRegion()); } void BalloonViewImpl::RepositionToBalloon() { |