| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/find_bar_controller.h" | 5 #include "chrome/browser/find_bar_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/find_bar.h" | 9 #include "chrome/browser/find_bar.h" |
| 10 #include "chrome/browser/tab_contents/navigation_entry.h" | 10 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 | 13 |
| 14 // The minimum space between the FindInPage window and the search result. | 14 // The minimum space between the FindInPage window and the search result. |
| 15 static const int kMinFindWndDistanceFromSelection = 5; | 15 static const int kMinFindWndDistanceFromSelection = 5; |
| 16 | 16 |
| 17 FindBarController::FindBarController(FindBar* find_bar) | 17 FindBarController::FindBarController(FindBar* find_bar) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 // static | 152 // static |
| 153 gfx::Rect FindBarController::GetLocationForFindbarView( | 153 gfx::Rect FindBarController::GetLocationForFindbarView( |
| 154 gfx::Rect view_location, | 154 gfx::Rect view_location, |
| 155 const gfx::Rect& dialog_bounds, | 155 const gfx::Rect& dialog_bounds, |
| 156 const gfx::Rect& avoid_overlapping_rect) { | 156 const gfx::Rect& avoid_overlapping_rect) { |
| 157 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { | 157 if (base::i18n::IsRTL()) { |
| 158 int boundary = dialog_bounds.width() - view_location.width(); | 158 int boundary = dialog_bounds.width() - view_location.width(); |
| 159 view_location.set_x(std::min(view_location.x(), boundary)); | 159 view_location.set_x(std::min(view_location.x(), boundary)); |
| 160 } else { | 160 } else { |
| 161 view_location.set_x(std::max(view_location.x(), dialog_bounds.x())); | 161 view_location.set_x(std::max(view_location.x(), dialog_bounds.x())); |
| 162 } | 162 } |
| 163 | 163 |
| 164 gfx::Rect new_pos = view_location; | 164 gfx::Rect new_pos = view_location; |
| 165 | 165 |
| 166 // If the selection rectangle intersects the current position on screen then | 166 // If the selection rectangle intersects the current position on screen then |
| 167 // we try to move our dialog to the left (right for RTL) of the selection | 167 // we try to move our dialog to the left (right for RTL) of the selection |
| 168 // rectangle. | 168 // rectangle. |
| 169 if (!avoid_overlapping_rect.IsEmpty() && | 169 if (!avoid_overlapping_rect.IsEmpty() && |
| 170 avoid_overlapping_rect.Intersects(new_pos)) { | 170 avoid_overlapping_rect.Intersects(new_pos)) { |
| 171 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { | 171 if (base::i18n::IsRTL()) { |
| 172 new_pos.set_x(avoid_overlapping_rect.x() + | 172 new_pos.set_x(avoid_overlapping_rect.x() + |
| 173 avoid_overlapping_rect.width() + | 173 avoid_overlapping_rect.width() + |
| 174 (2 * kMinFindWndDistanceFromSelection)); | 174 (2 * kMinFindWndDistanceFromSelection)); |
| 175 | 175 |
| 176 // If we moved it off-screen to the right, we won't move it at all. | 176 // If we moved it off-screen to the right, we won't move it at all. |
| 177 if (new_pos.x() + new_pos.width() > dialog_bounds.width()) | 177 if (new_pos.x() + new_pos.width() > dialog_bounds.width()) |
| 178 new_pos = view_location; // Reset. | 178 new_pos = view_location; // Reset. |
| 179 } else { | 179 } else { |
| 180 new_pos.set_x(avoid_overlapping_rect.x() - new_pos.width() - | 180 new_pos.set_x(avoid_overlapping_rect.x() - new_pos.width() - |
| 181 kMinFindWndDistanceFromSelection); | 181 kMinFindWndDistanceFromSelection); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 202 if (find_result.number_of_matches() > -1) { | 202 if (find_result.number_of_matches() > -1) { |
| 203 if (last_reported_matchcount_ > 0 && | 203 if (last_reported_matchcount_ > 0 && |
| 204 find_result.number_of_matches() == 1 && | 204 find_result.number_of_matches() == 1 && |
| 205 !find_result.final_update()) | 205 !find_result.final_update()) |
| 206 return; // Don't let interim result override match count. | 206 return; // Don't let interim result override match count. |
| 207 last_reported_matchcount_ = find_result.number_of_matches(); | 207 last_reported_matchcount_ = find_result.number_of_matches(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 find_bar_->UpdateUIForFindResult(find_result, tab_contents_->find_text()); | 210 find_bar_->UpdateUIForFindResult(find_result, tab_contents_->find_text()); |
| 211 } | 211 } |
| OLD | NEW |