diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 23:12:40 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 23:12:40 +0000 |
commit | 2aefa2dacd234b8f3237fb66b723b43ae9d4703a (patch) | |
tree | c4a9197af959a5cc7f4dc5a4f4d12f1288c9395b /chrome/browser | |
parent | db4ccd31523f692282867c1982443d06518c7d43 (diff) | |
download | chromium_src-2aefa2dacd234b8f3237fb66b723b43ae9d4703a.zip chromium_src-2aefa2dacd234b8f3237fb66b723b43ae9d4703a.tar.gz chromium_src-2aefa2dacd234b8f3237fb66b723b43ae9d4703a.tar.bz2 |
Clip compact location bar's window when animating.
- Moved window clipping code to DropdownBarHost so that CompactLocationBar can use it.
- Changed CompactLocationBar to do clipping when animating.
- Adjust the location of compact location bar when bookmark bar is visible.
CompactLocationBar's shape will be different from one for find bar.
I'll change the UpdateWindowEdge so that i can handle different shapes later.
BUG=31766
TEST=none
Review URL: http://codereview.chromium.org/560036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/compact_location_bar_host.cc | 20 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.cc | 121 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.h | 27 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host.cc | 124 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host.h | 22 |
5 files changed, 170 insertions, 144 deletions
diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc index 56e4eac..8449b65 100644 --- a/chrome/browser/chromeos/compact_location_bar_host.cc +++ b/chrome/browser/chromeos/compact_location_bar_host.cc @@ -137,8 +137,6 @@ gfx::Rect CompactLocationBarHost::GetDialogPosition( if (animation_offset() > 0) new_pos.Offset(0, std::min(0, -animation_offset())); - - // TODO(oshima): Animate the window clipping like find-bar. return new_pos; } @@ -147,6 +145,11 @@ void CompactLocationBarHost::SetDialogPosition(const gfx::Rect& new_pos, if (new_pos.IsEmpty()) return; + // Make sure the window edges are clipped to just the visible region. We need + // to do this before changing position, so that when we animate the closure + // of it it doesn't look like the window crumbles into the toolbar. + UpdateWindowEdges(new_pos); + // TODO(oshima): Animate the window clipping like find-bar. SetWidgetPositionNative(new_pos, no_redraw); } @@ -215,7 +218,18 @@ gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int index) const { // Try to center around the tab, or align to the left of the window. // TODO(oshima): handle RTL int x = std::max(tab_left_bottom.x() - ((width - bounds.width()) / 2), 0); - return gfx::Rect(x, tab_left_bottom.y(), width, 28); + int y; + if (browser_view()->IsBookmarkBarVisible() && + !browser_view()->GetBookmarkBarView()->IsDetached()) { + // Adjust the location to create the illusion that the compact location bar + // is a part of boolmark bar. + // TODO(oshima): compact location bar does not have right background + // image yet, so -2 is tentative. Fix this once UI is settled. + y = browser_view()->GetBookmarkBarView()->bounds().bottom() - 2; + } else { + y = tab_left_bottom.y(); + } + return gfx::Rect(x, y, width, 28); } void CompactLocationBarHost::Update(int index, bool animate_x) { diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc index 4e3e690..0bcd7aa 100644 --- a/chrome/browser/views/dropdown_bar_host.cc +++ b/chrome/browser/views/dropdown_bar_host.cc @@ -4,8 +4,11 @@ #include "chrome/browser/views/dropdown_bar_host.h" +#include "app/gfx/path.h" +#include "app/gfx/scrollbar_size.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/view_ids.h" @@ -17,6 +20,12 @@ #include "views/focus/view_storage.h" #include "views/widget/widget.h" +#if defined(OS_LINUX) +#include "app/scoped_handle_gtk.h" +#endif + +using gfx::Path; + // static bool DropdownBarHost::disable_animations_during_testing_ = false; @@ -181,9 +190,115 @@ void DropdownBarHost::ResetFocusTracker() { void DropdownBarHost::GetWidgetBounds(gfx::Rect* bounds) { DCHECK(bounds); - // The BrowserView does Layout for the components that we care about - // positioning relative to, so we ask it to tell us where we should go. - *bounds = browser_view_->GetFindBarBoundingBox(); + *bounds = browser_view_->bounds(); +} + +void DropdownBarHost::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 + // window. Basically, it encompasses only the visible pixels of the + // concatenated find_dlg_LMR_bg images (where LMR = [left | middle | right]). + 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 (animation_offset() > 0) { + // The animation happens in two steps: First, we clip the window and then in + // GetWidgetPosition 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 = animation_offset(); + // |y| shrinking means the animation (visible) region gets larger. In other + // words: the rectangle grows upward (when the widget 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 widget_bounds; + GetWidgetBounds(&widget_bounds); + + // Calculate how much our current position overlaps our boundaries. If we + // overlap, it means we have too little space to draw the whole widget and + // we allow overwriting the scrollbar before we start truncating our widget. + // + // 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 - widget_bounds.width() - + gfx::scrollbar_size() + 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()); } void DropdownBarHost::RegisterEscAccelerator() { diff --git a/chrome/browser/views/dropdown_bar_host.h b/chrome/browser/views/dropdown_bar_host.h index 04e0c51..8b71b12 100644 --- a/chrome/browser/views/dropdown_bar_host.h +++ b/chrome/browser/views/dropdown_bar_host.h @@ -109,18 +109,21 @@ class DropdownBarHost : public views::AcceleratorTarget, // Returns the animation offset. int animation_offset() const { return animation_offset_; } - // Retrieves the boundaries that the dropdown widget has to work with - // within the Chrome frame window. The resulting rectangle will be a - // rectangle that overlaps the bottom of the Chrome toolbar by one - // pixel (so we can create the illusion that the dropdown widget is - // part of the toolbar) and covers the page area, except that we - // deflate the rect width by subtracting (from both sides) the width - // of the toolbar and some extra pixels to account for the width of - // the Chrome window borders. |bounds| is relative to the browser - // window. If the function fails to determine the browser - // window/client area rectangle or the rectangle for the page area - // then |bounds| will be an empty rectangle. - void GetWidgetBounds(gfx::Rect* bounds); + // Retrieves the boundary that the dropdown widget has to work with + // within the Chrome frame window. The boundary differs depending on + // the dropdown bar implementation. The default implementation + // returns the boundary of browser_view and the drop down + // can be shown in any client area. + virtual void GetWidgetBounds(gfx::Rect* bounds); + + // The find bar widget needs rounded edges, so we create a polygon + // that corresponds to the background images for this window (and + // make the polygon only contain the pixels that we want to + // draw). The polygon is then given to SetWindowRgn which changes + // the window from being a rectangle in shape, to being a rect with + // curved edges. We also check to see if the region should be + // truncated 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(). diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc index 2e9d8ec..4a7a553 100644 --- a/chrome/browser/views/find_bar_host.cc +++ b/chrome/browser/views/find_bar_host.cc @@ -4,11 +4,8 @@ #include "chrome/browser/views/find_bar_host.h" -#include "app/gfx/path.h" -#include "app/gfx/scrollbar_size.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,12 +20,6 @@ #include "views/widget/root_view.h" #include "views/widget/widget.h" -#if defined(OS_LINUX) -#include "app/scoped_handle_gtk.h" -#endif - -using gfx::Path; - namespace browser { // Declared in browser_dialogs.h so others don't have to depend on our header. @@ -140,114 +131,6 @@ bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position, return true; } -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 - // window. 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 (animation_offset() > 0) { - // The animation happens in two steps: First, we clip the window and then in - // GetWidgetPosition 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 = animation_offset(); - // |y| shrinking means the animation (visible) region gets larger. In other - // words: the rectangle grows upward (when the widget 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 widget_bounds; - GetWidgetBounds(&widget_bounds); - - // Calculate how much our current position overlaps our boundaries. If we - // overlap, it means we have too little space to draw the whole widget and - // we allow overwriting the scrollbar before we start truncating our widget. - // - // 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 - widget_bounds.width() - - gfx::scrollbar_size() + 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 widget_bounds; @@ -299,6 +182,13 @@ void FindBarHost::SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) { SetWidgetPositionNative(new_pos, no_redraw); } +void FindBarHost::GetWidgetBounds(gfx::Rect* bounds) { + DCHECK(bounds); + // The BrowserView does Layout for the components that we care about + // positioning relative to, so we ask it to tell us where we should go. + *bounds = browser_view()->GetFindBarBoundingBox(); +} + void FindBarHost::RestoreSavedFocus() { if (focus_tracker() == NULL) { // TODO(brettw) Focus() should be on TabContentsView. diff --git a/chrome/browser/views/find_bar_host.h b/chrome/browser/views/find_bar_host.h index 51771c9..5f1a458 100644 --- a/chrome/browser/views/find_bar_host.h +++ b/chrome/browser/views/find_bar_host.h @@ -96,16 +96,20 @@ class FindBarHost : public DropdownBarHost, // sized, and should not be redrawn to reduce update flicker. virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw); - private: - // The find bar widget needs rounded edges, so we create a polygon - // that corresponds to the background images for this window (and - // make the polygon only contain the pixels that we want to - // draw). The polygon is then given to SetWindowRgn which changes - // the window from being a rectangle in shape, to being a rect with - // curved edges. We also check to see if the region should be - // truncated to prevent from drawing onto Chrome's window border. - void UpdateWindowEdges(const gfx::Rect& new_pos); + // Retrieves the boundaries that the find bar widget has to work with + // within the Chrome frame window. The resulting rectangle will be a + // rectangle that overlaps the bottom of the Chrome toolbar by one + // pixel (so we can create the illusion that the dropdown widget is + // part of the toolbar) and covers the page area, except that we + // deflate the rect width by subtracting (from both sides) the width + // of the toolbar and some extra pixels to account for the width of + // the Chrome window borders. |bounds| is relative to the browser + // window. If the function fails to determine the browser + // window/client area rectangle or the rectangle for the page area + // then |bounds| will be an empty rectangle. + virtual void GetWidgetBounds(gfx::Rect* bounds); + private: // Allows implementation to tweak widget position. void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect); |